in reply to Re: Converting negative number to binary with specific width
in thread Converting negative number to binary with specific width
I was thinking something more along the lines of
to get closer to the 'b' formatting of sprintf (although I'm not sure this is any better than substr-inging it). (Update: Also see perlpacktut.)c:\@Work\Perl\monks>perl -wMstrict -le "for my $n (-2, -1, 0, 1, 2, 1023, 1024, 1025) { my $bin = reverse unpack 'b10', pack 'v', $n; print qq{'$bin' <= $n}; } " '1111111110' <= -2 '1111111111' <= -1 '0000000000' <= 0 '0000000001' <= 1 '0000000010' <= 2 '1111111111' <= 1023 '0000000000' <= 1024 '0000000001' <= 1025
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Converting negative number to binary with specific width
by Anonymous Monk on Nov 03, 2015 at 06:31 UTC | |
by Anonymous Monk on Nov 03, 2015 at 07:35 UTC | |
by Anonymous Monk on Nov 03, 2015 at 07:44 UTC | |
by AnomalousMonk (Archbishop) on Nov 03, 2015 at 10:33 UTC |