in reply to encoding BigInts: TIMTOWTDI but any good way?
One way:
use Math::BigInt; $x = Math::BigInt->new(5000000000); print($x->as_hex(), $/); die("This doesn't work on negative numbers.\n") if $x->is_neg(); my $packed = ''; while (!$x->is_zero()) { $y = $x->copy()->bmod(256); $packed = pack('C', $y) . $packed; $x->brsft(8); } print('0x', unpack('H*', $packed), $/); # Verify work.
Since you're packing, you're probably expecting a fixed size result. If so, this can be modified to handle negative numbers and to return a fixed size result.
|
|---|