R
RFleming
I am using a program that converts decimal to BCD and Back Again.
While running code I noticed that somehow the conversion is not
handled correctly. for example run the code below:
For i As Int16 = 10 To 99
Dim str1 As String =
Microsoft.VisualBasic.Left(i.ToString, 1)
Dim str2 As String =
Microsoft.VisualBasic.Right(i.ToString, 1)
Dim aByte As Byte
aByte = (CInt(str1 * 16) Or
CInt(str2)) 'Put variable i into aByte in
BCD
Debug.Print(((aByte / 16 And &HF) * 10 + (aByte And
&HF)).ToString) 'Convert Back To Decimal and Print
Next i
For some reason numbers ending in 8 and 9 for the most part get
multiplied by 10, (19 comes back 29, 99 comes back 109) Anyone now
what I am doing wrong? Or is this a problem with the compiler?
Thanks
Ryan
While running code I noticed that somehow the conversion is not
handled correctly. for example run the code below:
For i As Int16 = 10 To 99
Dim str1 As String =
Microsoft.VisualBasic.Left(i.ToString, 1)
Dim str2 As String =
Microsoft.VisualBasic.Right(i.ToString, 1)
Dim aByte As Byte
aByte = (CInt(str1 * 16) Or
CInt(str2)) 'Put variable i into aByte in
BCD
Debug.Print(((aByte / 16 And &HF) * 10 + (aByte And
&HF)).ToString) 'Convert Back To Decimal and Print
Next i
For some reason numbers ending in 8 and 9 for the most part get
multiplied by 10, (19 comes back 29, 99 comes back 109) Anyone now
what I am doing wrong? Or is this a problem with the compiler?
Thanks
Ryan