Obvious Programming Tip: Check Those Bit Patterns

RedonkulouslyLargeNumber.png

Sometimes, when tracking down a bug, you’ll get a bit of console spew, an exception log, or a crash log that contains a ridiculously large number. Sometimes, that is the result of a memory smasher.

Sometimes, though, it is because of a type conversion problem.

For example, if you see a log message indicating that the value 4294967295 is causing a problem, it is probably because something archived -1 on a 32 bit system and then unarchived it on 64 bit improperly.

This has come up often enough that I like to leave the Calculator app open in Programmer Mode. Then, I can copy/paste the value into Calculator and see both the bit pattern or the hex value (which will often show patterns that base-10 does not).

An aside, I have generally tried to break myself of the habit of relying upon knowledge of magic values (like 4294967295). Sure, I’ll use ’em as clues, but I focus much more on refining my tools to make recognition of said values unnecessary as there are a slew of different values that look non-obvious in decimal form that become darned obvious in binary or hex.

Dead obvious, I know.



Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>