in reply to Re^5: Displaying bit-vectors with Most Significant Bits to the left?
in thread Displaying bit-vectors with Most Significant Bits to the left?
I believe you, but how do you reliably check the output?
Whether using vec, pack or some other means, there are two ways: Reading the documentation, or testing experimentally on the appropriate machines.
And what does "same output" exactly mean?
For the code in Re: Displaying bit-vectors with Most Significant Bits to the left?, the topic was producing 0000011100000101 from $m0.
For the code in Re^2: Displaying bit-vectors with Most Significant Bits to the left?, the topic was producing a string consisting of the byte 0b00000111 followed by the byte 0b00000101.
I did machine programming on big-endian architectures, I don't know what to trust anymore. Do I need to check with Devel::Peek to be sure?
Check what? If pack or vec produced the expected strings? Devel::Peek::Dump would be too noisy. I'd use one of the following:
sprintf "%v02X", $bytes unpack 'H*', $bytes
For example,
$ perl -e' for my $format (qw( n v )) { my $bytes = pack($format, 0x1234); CORE::say sprintf "%v02X", $bytes; CORE::say unpack "H*", $bytes; } ' 12.34 1234 34.12 3412
|
|---|