It can be difficult to see how other number systems (such as binary and hexadecimal) work since they have a different amount of numerals than the ten numerals of decimal. But imagine that you are counting in these number systems using an old-fashioned analog odometer that has a different amount of numerals for each digit.

The following three odometers **always show the same number**, but they are written out differently in different number systems:

Decimal (Normal, base-10 with digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9):

Binary (base-2 with digits 0, 1):

Hexadecimal (base-16 with digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F):

UPDATE: Source code for Gavin Brock’s JavaScript odometers. Source code for this binary/decimal/hexadecimal demo all on a single page.

Technically they do not always show the same number, since the binary odometer rolls over before the other two.

I’m not sure I understand your comment. The rolling for all the digits happens simultaneously.

I mean when the binary one gets to 11111111, in the next increment it resets to 0000000, while the decimal and hexadecimal ones keep going up. In order to keep the same number they should all reset to 0000000 at the same time.

TheBlackCat is right. The maximum number that can be shown on the binary odometer is 255 whereas the maximum number on the base-10 odometer is 99,999,999. So in order for the binary odometer to roll over at the same time is the base-10 odometer you need to add more digits to the binary odometer.

I’ve fixed the rollover bug that the other commenters have pointed out.

Mr. Sweigart Sir – Could you possible provide the javascript source for your odometers? If not, that’s ok. It would be helpful to my learning, but if you choose not to, I completely respect your decision to do so. At any rate, I thank you for promoting learning and open source Sir.

I admire you for placing the free copy online. Obviously, this costs you quite a few sales, and in the end, money. Those of us out of work can get the benefit of your excellent books. I will send you what I can as soon as I can. What I can do is urge my friends with more money than I have to buy them.

You demonstrate that you live what you preach, and that is lacking in too many ‘earthmen.’ (earthwomen?) (earthpersons?) Thanks for you effort.

Don Weingarten

[email protected]

I Always want to show digits up to two places for example 555.00 for decimal numbers . what it does just convert the Digit to 555 after the increment and do not show the digits after decimal