sub bigint_to_bytearray { my $bigint = shift; die "Negative numbers not supported" if $bigint < 0; my @bytes = unpack('c*', pack('H*', substr($bigint->as_hex, 2))); unshift @bytes, 0x00 if $bytes[0] < 0; # Add sign bit if necessary return @bytes; }