Skip to content

Comment on Your birthdate in the decimal expansion of Pi

Comments

I wonder if there is not a bug in the decompress program:

  for (i = 0; i < FILE_SIZE; i++) {
    printf("%d%d", (buf[i]&0xf0)>>4, buf[i] & 0xf);
  }
Shouldn't this be >>8 ?

(buf[i]&0xf0) >> 8 would be zero (always).

One hex digit (0x0f) is 4 bits wide, not 8 (one byte <=> two hex digits).

No, it's extracting the upper 4 bits of the byte, not the upper 8 bits of a 16-bit quantity.

This is actually a quite standard number format. Real computers like the 6502 http://www.6502.org/tutorials/decimal_mode.html and the IBM zSeries have harware support for that encoding http://en.wikipedia.org/wiki/Binary-coded_decimal#Packed_BCD and there are decoder chips like the 74LS48 that directly translate these nibbles to 7-segment display numbers.

Doh, of course.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.