Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Encoding BCD

by Aim9b (Monk)
on Jun 13, 2007 at 16:06 UTC ( #621010=note: print w/replies, xml ) Need Help??

in reply to Re: Encoding BCD
in thread Encoding BCD

Corion, Thanks for the help, I especially like the debug piece at the end. My DecodeBCD is working (thanks in no small part to FunkyMonk), it's the ENcoding I'm having a problem with. getting from the 3 substrings, BACK to the \x12\x34..etc. Thanks.

Replies are listed 'Best First'.
Re^3: Encoding BCD
by Corion (Pope) on Jun 13, 2007 at 16:14 UTC

    The following code works for me:

    use strict; use Test::More tests => 3; sub encode_BCD { return pack 'H*', join '', @_ }; is encode_BCD("123456"), "\x12\x34\x56"; is encode_BCD("00",3456),"\x00\x34\x56"; is encode_BCD("1",2),"\x12";
      I don't get it - aren't you just encoding it to Hex? That's not the same as BCD is it?

        Packed Binary-coded decimals are a subset of hexadecimal numbers, except that their values are to be interpreted differently. But as we're encoding strings that have only decimal digits in them, just treating these decimal digits as hexadecimal digits results in the wanted packed bcd values. If you don't trust it, just look at that the tests return the wanted values.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://621010]
[Your Mother]: The good news is, they think they are influencing people but Americans at least are irretrievably biased. All that can be accomplished is a little spike in domestic violence. :P
[LanX]: YM: watch your mouth or I'll show up with my automatic gun at your nursery ...
[LanX]: ;-P
[LanX]: What I learned now is to hide my friends list at FB (not that I have many ...)
[Your Mother]: Careful. They're listening!
[LanX]: I mean hiding my friends FROM my friends
[Your Mother]: Yeah. I don't know what they expect. If a stranger can see the post or list or whatever, so can a harvesting program.
[Your Mother]: HA.
[NodeReaper]: he's already hiding from me :(

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2018-03-19 13:29 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.