Skip to main content

Practice ยท 6 of 6

Representation Copy

CHALLENGE
Difficulty: advanced+25 XP

Implement unsigned int rep_bytes(double d) that returns the number of leading zero **bytes** in d's object representation on this little-endian platform. Copy the double's bytes via memcpy into an unsigned char array, then scan from the highest index (most significant byte) downward while bytes are zero. - rep_bytes(1.0) is 0: 1.0 is 0x3FF0000000000000, whose most significant byte (index 7, little-endian) is 0x3F โ€” nonzero, so the scan stops immediately. - rep_bytes(0.0) is 8: every representation byte of +0.0 is zero. - rep_bytes(5e-324) is 7: the smallest positive subnormal is 0x0000000000000001 โ€” its single nonzero byte is index 0, so exactly the seven bytes above it are zero.

Back to lesson: Practice: Object Layout Forensics