3 ms·
Questioning the wisdom of saying this on the public internet, but the first line of the first file has caught me up. What is the purpose of this function, from
by euroclydon 14y ago
Questioning the wisdom of saying this on the public internet, but the first line of the first file has caught me up.
What is the purpose of this function, from the clock emulator:
function formatter(a) { return ((a / 10) << 4) | (a % 10);}
- mikeash 14y agoLooks like a converter to BCD. It'll take e.g. 42 and turn it into 0x42. No clue why this would be necessary, but that looks like what it does.
- sounds 14y agoYes, some links on why BCD: http://wiki.osdev.org/RTC http://wiki.osdev.org/RTC http://wiki.osdev.org/CMOS#Format_of_Bytes http://wiki.osdev.org/CMOS#Format_of_Bytes
- mikeash 14y agoThanks for the links. And, holy crap is PC hardware bizarre.
- Someone 14y agoBCD isn't _that_ bizarre. Many architectures had and have instructions for BCD arithmetic: x86: http://en.wikipedia.org/wiki/Intel_BCD_opcode http://en.wikipedia.org/wiki/Intel_BCD_opcode 68k: http://meseec.ce.rit.edu/eecc250-winter99/250-1-20-2000.pdf http://meseec.ce.rit.edu/eecc250-winter99/250-1-20-2000.pdf 6502: http://www.6502.org/users/dieter/bcd/bcd_0.htm http://www.6502.org/users/dieter/bcd/bcd_0.htm 6800: http://fundamentals-digital-electronics.blogspot.com/2010/09/motorola-6800-eight-bit-microprocessor.html http://fundamentals-digital-electronics.blogspot.com/2010/09... Several others, such as Power6 and Sparc64: http://speleotrove.com/decimal/ http://speleotrove.com/decimal/ (also shows this is is both still useful today)
- alexkus 14y agoWhy don't you try it for a bunch of input values and find out yourself? Hint: 0->0, 1->1, ..., 9->9, 10->16, ..., 19->25, 20->32, 29->41, 30->48, ...
- euroclydon 14y agoI did. But I don't understand the purpose. Something to do with hex?