# Decimal, Binary, and Hexadecimal Odometers

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):

## 8 thoughts on “Decimal, Binary, and Hexadecimal Odometers”

1. TheBlackCat says:

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

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

2. TheBlackCat says:

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.

3. Jordan says:

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.

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

5. Paul Thomas says:

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.

6. 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.

7. NitinJ says:

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