Hi guys, I'm sure this question has come up before, but I can't make a decent search query that turns up anything useful. Why does it appear that 0 (zero, 0x00) has non-zero bits in it? This came up when I tracked down a bug that ultimately reduced to:
% perl -le 'print vec(0x0, 5,1)'
1
Strange! But:
% perl -le 'print vec(0x0, 6,1)'
0
Huh? And:
% perl -le 'print vec("", 5,1)'
0
I thought "" would be the same as 0 in memory -- all 0 bits!
So I naturally looked up the perldoc on vec(), and tried out this:
% perl -le '@bits = split(//, unpack("b*", 0x0)); print "@bits"'
0 0 0 0 1 1 0 0
What gives? Can anyone explain to me why 0 has two non-zero bits in it? And is the only real solution to my bug to just use bit operations rather than vec() (ugh!) Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.