Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Binary Coded Decimal

by Anonymous Monk
on Sep 18, 2012 at 01:44 UTC ( #994166=note: print w/replies, xml ) Need Help??


in reply to Binary Coded Decimal

perl pack bcd -> BCD Clock built using only binary logic., Encoding BCD

so

sub encode_BCD { return pack 'H*', join '', @_ }

If you need to ensure < 99 , or dealing with signs properly, you'll have to add that part

Seems to work https://en.wikipedia.org/wiki/Binary_coded_decimal

-1,234,56 0001 0010 0011 0100 0101 0110 0111 1101 1 2 3 4 5 6 7 - $ perl -le " print join q/ /, split /....\K/, unpack q/B*/, pack q/H*/ +, q/1234567-/ " 0001 0010 0011 0100 0101 0110 0111 1101 $ perl -le " print join q/ /, unpack q/(A4)*/, unpack q/B*/, pack q/H* +/, q/1234567-/ " 0001 0010 0011 0100 0101 0110 0111 1101

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994166]
help
Chatterbox?
[choroba]: also, seeing communist propaganda I remember from my childhood... very strange experience
[LanX]: ha the Cuban experience
[LanX]: one strange thing I heard was that pharmacies in Vietnam are run by Russians

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2017-02-26 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (371 votes). Check out past polls.