From: Duane Bozarth on
Randy Birch wrote:
>
> Like this? ...
>
....snip sample code...

> 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/

I hesitated to jump in here as I (like apparently most others) am
totally confused by the description given by OP of what is really
wanted/needed by the hardware.

I'm thinking this sounds like documentation for some piece of hardware
written in what passes as an English translation--I've had a few
Advantech boards recently that were candidates for a contest of
poor/misleading/erroneous documentation. :(

Hopefully OP will tell us if one of the guesses so far happens to
actually solve his problem or can provide a more complete description of
the hardware and its descriptive usage if not...
From: DanS on
John Morley <jmorley(a)nospamanalysistech.com> wrote in news:ugxYLKbzFHA.3000
@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
>

Hi John,

I didn't even know that BCD was used like this, as I've only used it in
rotary switches. I'm not exactly sure why this would be used. Sending "10"
as a string would be 2 bytes, and BCD would be 1, but just straight binary
would be one also.

So the others know, here's an article:

http://www.danbbs.dk/~erikoest/bcd.htm

Specifically, your talking about packed-BCD. Each digit is represented by 4
bits of a byte.

As per your example, October, month 10, BCD=16.....

0000 0000 = 1 Byte
0001 = 1
0000 = 0

00010000 = 16 in BCD

I got this to work with some long code that had 3 functions, but while
looking at the output, and noticed a pattern.

Since one byte represents 2 digits, the following works on a 2 digit number
up to 99. That may be an easy limitation to work with.

CodeBegin
-----------------------------------------------------
Public Function BCDxx(decNum As Integer) As Integer

BCDxx = Int(decNum / 10) * 16
BCDxx = BCDxx + (decNum Mod 10)

End Function
-----------------------------------------------------
CodeEnd

That's what the pattern worked out to be, I can post the long code if
needed.

But, simple is almost always better.

Regards,

DanS
From: Mark Yudkin on
Basically, you scan through the value dividing by 10, grab the remainder,
and accumulate on a nybble-basis. The problem with doing it in native VB6 is
that you have to do it yourself, rather than taking advantage of the Intel
hardware instruction for doing it.?For this reason, I don't have any native
VB6 code, but instead call into a BCD package.

"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: Dave on
John

I suppose that if you look at it like that then "10" = "16" is sort of true,
I'm so used to binary and BCD that I make the conversion automatically and
would never look at it like that.

There is I'm sure proper ways to go about this but if you are only
interested in month values from 1 to 12 why not just add 6 to numbers above
9 thus:

if n > 9 then n = n + 6

that will give you 16,17 & 18 for 10, 11 & 12 repectively.

Regards
Dave.

"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: Mike Williams on
"Dave" <nobody(a)nowhere.com> wrote in message
news:eVreBSbzFHA.3588(a)tk2msftngp13.phx.gbl...

> 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.

I think that's a little bit harsh, Dave. After all nobody (yet) is quite
sure what John really wants (mostly because his example makes it difficult
to come to any sensible deduction). Perhaps he'll post again and make his
requirements clear. You're of course right in saying that the BCD for
decimal 10 is two bytes - but that only applies to one kind of BCD. Another
kind of BCD (which was often used when I was "into" electronics many years
ago) was what is now called "packed BCD", in which each decimal number is
held in one "nibble" (there being, of course, two nibbles in every byte).
Back then most of us (at least most of the people I knew) used to simply
call it "BCD", rather than "packed BCD", simply because that is what we were
used to working with. However, in BCD the decimal number 10 would be held in
two bytes as (in hex representation to make things clear) &H010A and the
same decimal number 10 as "packed BCD" would be held in one byte as &H1A.

Personally I think it might be wise to wait un til the OP posts again so
that we know exactly what his requirements are.

Mike





First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Transparent Picturebox
Next: Error from Hell: Overflow