3 ms·
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'
by zak_mc_kracken 12y ago
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 ?
- myrmidon 12y ago(buf[i]&0xf0) >> 8 would be zero (always). One hex digit (0x0f) is 4 bits wide, not 8 (one byte <=> two hex digits).
- gjm11 12y agoNo, it's extracting the upper 4 bits of the byte, not the upper 8 bits of a 16-bit quantity.
- zak_mc_kracken 12y agoDoh, of course.
- fhars 12y agoThis is actually a quite standard number format. Real computers like the 6502 http://www.6502.org/tutorials/decimal_mode.html 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 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.