Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Encoding BCD

by Corion (Patriarch)
on Jun 13, 2007 at 16:14 UTC ( [id://621014]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Encoding BCD
in thread Encoding BCD

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";

Replies are listed 'Best First'.
Re^4: Encoding BCD
by Anonymous Monk on Feb 27, 2009 at 22:48 UTC
    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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://621014]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-03-19 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found