Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I convert this F23CC481AAE190180000000014000008 big hexadecimal number to binary anyway?

Replies are listed 'Best First'.
Re: Hexadecimal to binary
by almut (Canon) on Jun 16, 2010 at 15:51 UTC
    my $bin = pack("H*", "F23CC481AAE190180000000014000008"); # + $bin is a 16-byte/128-bit value

    Or. visualized as an ASCII bitstring:

    print unpack("B*", pack("H*", "F23CC481AAE190180000000014000008")); # + "1111001000111100110..."
Re: Hexadecimal to binary
by toolic (Bishop) on Jun 16, 2010 at 15:47 UTC
    One way:
    use strict; use warnings; my $h = 'F23CC481AAE190180000000014000008'; my $bin; $bin .= sprintf '%04b', hex $_ for split //, $h; print $bin; __END__ 1111001000111100110001001000000110101010111000011001000000011000000000 +0000000000000000000000000000010100000000000000000000001000

    See also:

Re: Hexadecimal to binary
by JavaFan (Canon) on Jun 16, 2010 at 16:35 UTC
    $ (echo ibase=16; echo obase=2; echo F23CC481AAE190180000000014000008) + | BC_LINE_LENGTH=200 bc 1111001000111100110001001000000110101010111000011001000000011000000000 +0000000000000000000000000000010100000000000000000000001000
    HTH. HAND.
Re: Hexadecimal to binary
by BrowserUk (Patriarch) on Jun 16, 2010 at 19:05 UTC

    If you want to actually do something with the converted binary number, and can live with the precision loss, then this should work on any version of Perl.

    It just breaks the 128-bit hex into 4 x 32-bit lumps, converts them to numbers and multiplies them out:

    $h = 'F23CC481AAE190180000000014000008';; $n = 0.0; ( $n *= 2**32 ) += unpack 'N', pack 'H*', $_ for unpack '(A8)*', $h;; print $n;; 3.21988698417062e+038 printf "%.f\n", $n;; 321988698417062150000000000000000000000

    Which compared to the full precision value: 321988698417062151410473125841815470088, represents an inaccuracy of 0.00000000000000043805% Very few applications need more.

    To put that into perspective, it represents just 19 seconds on the age of the universe.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Hexadecimal to binary
by Anonymous Monk on Jun 16, 2010 at 15:34 UTC
    How can I convert this F23CC481AAE190180000000014000008 big hexadecimal number to binary anyway?

    Pay a professional