Prev: Transparent Picturebox
Next: Error from Hell: Overflow
From: John Morley on 10 Oct 2005 12:38 Randy, I think you are right, although the controller manual I am using does call the data "BCD"...... OK, so how do I programmatically convert the 10 to a 16? In your example, I see how you do it in the Immediate window (?&H10), but how do I do that in code? For example, I am trying to convert the month using: iMonth = Month(mydate) This returns "10" for October. I need to convert the "10" to a "16" to pass to the controller..... Thanks! John Randy Birch wrote: > The BCD of 10 is 0001 0000, not 16. Using your examples (10 >16) it > appears you are talking decimal>hex, ... > > ?&H10 > 16 > ?hex(16) > 10 >
From: Veign on 10 Oct 2005 12:39 So you are looking for a routine that take a decimal number converts it to BCD then reads the value as Binary and spits out the decimal equivalent? Like: Input: 25 Internal: 0010 0101 Output: 37 -- Chris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp Veign's Blog http://www.veign.com/blog -- "John Morley" <jmorley(a)nospamanalysistech.com> wrote in message news:OOb8VhbzFHA.1444(a)TK2MSFTNGP10.phx.gbl... > Hi, > > Hmmm, perhaps I didn't ask the right question? The value "10" is made up > of two digits "1" and "0". "1" is represented as 0001, and "0" is 0000. > Put together, this becomes 00010000 which is decimal 16. I need a routine > to make this conversion (10 --> 16). > > Thanks, > > John > > > > Dave wrote: >> John >> >> I think you should go and do some research into BCD. >> >> The BCD for 10 is 2 bytes, one of 1 and one of 0. >> In BCD is each decimal number expressed in binary so 1 to 12 is >> >> 1 0000 0001 >> 2 0000 0010 >> 3 0000 0011 >> 4 0000 0100 >> 5 0000 0101 >> 6 0000 0110 >> 7 0000 0111 >> 8 0000 1000 >> 9 0000 1001 >> 10 0001 0000 >> 11 0001 0001 >> 12 0001 0010 >> >> Best Regards >> Dave O. >> >> "John Morley" <jmorley(a)nospamanalysistech.com> wrote in message >> news:ugxYLKbzFHA.3000(a)TK2MSFTNGP12.phx.gbl... >> >>>Hi All, >>> >>>Is there a handy way to convert a decimal value to it's equivalent BCD >>>representation in VB?? I need to send some data to a controller that >>>expects date data in BCD. For example the month of October (decimal 10) >>>would be sent as "16" (BCD equivalent of 10). >>> >>>Thanks! >>> >>>John >> >>
From: Jim Mack on 10 Oct 2005 12:47 John Morley wrote: > Hi, > > Hmmm, perhaps I didn't ask the right question? The value "10" is made > up of two digits "1" and "0". "1" is represented as 0001, and "0" is > 0000. Put together, this becomes 00010000 which is decimal 16. I need > a routine to make this conversion (10 --> 16). > OK, what you're describing is 'packed BCD", which is a lot like hex, viewed as a binary byte. Do you want a string that has the two characters "1" and "6", or just the value 16? Try something like this: Result = ((Dec \ 10) * 16) + (Dec Mod 10) Res$ = Hex$(Result) -- Jim Mack MicroDexterity Inc www.microdexterity.com
From: Rick Rothstein [MVP - Visual Basic] on 10 Oct 2005 13:33 > > Hmmm, perhaps I didn't ask the right question? The value "10" is made > > up of two digits "1" and "0". "1" is represented as 0001, and "0" is > > 0000. Put together, this becomes 00010000 which is decimal 16. I need > > a routine to make this conversion (10 --> 16). > > > > OK, what you're describing is 'packed BCD", which is a lot like hex, viewed as a binary byte. > > Do you want a string that has the two characters "1" and "6", or just the value 16? That would be one of my questions. The other would be to ask what the OP wants for numbers like 123 or 4567 or those containing more digits. Rick
From: Randy Birch on 10 Oct 2005 16:02 Like this? ... Private Sub Command1_Click() Dim nMonth As Variant Dim hexMonth As Variant Dim decMonth As Variant nMonth = Month(Now) Debug.Print nMonth, TypeName(nMonth) hexMonth = "&H" & nMonth Debug.Print hexMonth, TypeName(hexMonth) decMonth = CInt(hexMonth) Debug.Print decMonth, TypeName(decMonth) End Sub > 10 Integer &H10 String 16 Integer .... or as a function ... Private Sub Command2_Click() Dim cnt As Integer For cnt = 1 To 12 Print IntAsHex(cnt) Next End Sub Private Function IntAsHex(nInt As Integer) As Integer IntAsHex = CInt("&H" & nInt) End Function Seems to work for 1- through 19 but it's strange not using the A-F values in hex. For reference (comparison) see http://www.htservices.com/Reference/NumberSystemConversions/ -- Randy Birch MS MVP Visual Basic http://vbnet.mvps.org/ ---------------------------------------------------------------------------- Read. Decide. Sign the petition to Microsoft. http://classicvb.org/petition/ ---------------------------------------------------------------------------- "John Morley" <jmorley(a)nospamanalysistech.com> wrote in message news:eLUCdkbzFHA.3812(a)TK2MSFTNGP09.phx.gbl... : Randy, : : I think you are right, although the controller manual I am using does : call the data "BCD"...... OK, so how do I programmatically convert the : 10 to a 16? In your example, I see how you do it in the Immediate window : (?&H10), but how do I do that in code? : : For example, I am trying to convert the month using: : : iMonth = Month(mydate) : : This returns "10" for October. I need to convert the "10" to a "16" to : pass to the controller..... : : Thanks! : : John : : Randy Birch wrote: : : > The BCD of 10 is 0001 0000, not 16. Using your examples (10 >16) it : > appears you are talking decimal>hex, ... : > : > ?&H10 : > 16 : > ?hex(16) : > 10 : >
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Transparent Picturebox Next: Error from Hell: Overflow |