50 lines of code_ understanding different number systems


• Reading numbers in any number system can be done by multiplying each digit value with a power of the base, starting with the zero-th power for the right most digit and increasing the exponent by one for each step to the left, e.g. Us dollar exchange rate to malaysian ringgit 123 = 3×10^0 + 2×10^1 + 1×10^2 for decimal numbers (base 10)

We are very used to the decimal system. How to read binary We learned this system as young kids and use it nearly all the time in our day to day life. Binary to denary converter Since we are so familiar with it, it does feel “natural” for us to use ten symbols (0, 1, …, 9) to count.

Besides the fact that most of us happen to have ten fingers and ten toes (which kids often use as support when counting) there’s not much “natural” about it, we might as well use more or less symbols to count just as well.

• When we define time in hours, we have a base of 60 minutes that we could hypothetically express with 60 different symbols to get easier conversion between hours and minutes

Computers, being digital systems themselves, use 8 digits of two symbols (aka “bits”, wich can take two values each) grouped together as a byte, which can hold 256 (2 8) different values.

Using decimal numbers it is not easy to spot how many byte a number will take up. Funny jokes tagalog 2016 In contrast, knowing that the hexadecimal system with 16 symbols 0, …, 9, A (10), B (11), C (12), D (13), E (14) and F (15) is easier for this purpose. Nzd to usd conversion Two digits of any hexadecimal number take up one byte.

Knowing this, finding out how many bytes the number 10895 takes is trivial if this number is written in hexadecimal instead of decimal: 10895 (decimal) = 2a8f (hex) = 2 bytes

This comes in handy when we need to deal with data that is too big to fit into a single byte but we want to access it byte-wise. Binary conversion table In that case we can work with each pair of digits independently (for our last example we would work with 2a and 8f independently). Cnn futures stock market Reinventing numbers with Emoji

Note that this association is arbitrary. Binary domain steam We just give each symbol a specific meaning, but which symbol means what and even which symbols we picked doesn’t matter, as long as we stick to the meaning once we’ve defined it.

After this we need to become inventive. Usd zar exchange We could use more emojis and simply have more symbols for numbers. Pound to dollar conversion rate today Now let’s say we can’t have more than the three symbols (maybe we are communicating via a set of printed tiles and all our tiles are divided into the three symbols).

Another way of counting more things is by chalking up how often we have gone through all of our three symbols. Market index futures So when we count to five, we would do: ★, ♥, ☻, ♥★, ♥♥, ♥☻

Once we reach “☻”, the biggest digit in our system, we know we’ve gone through all of our symbols, so we remember that we did that full walk through once (or “♥” times, as we express that in our symbols) and start from zero (aka ★) behind it. Usd to nzd forecast Any reader who knows the meaning of our symbol system then sees “They went through all the symbols once and that’s it, so the number must be the one after “two”.

If this looks weird, think it through with our decimal system: We use 10 symbols (0-9) and once we run out, we start chalking up how much we ran through our symbols before: (8, 9, 10, 11,…, 19, 20, 21,…, 99, 100, 101,…).

If you look at the decimal numbers digit-by-digit, you may say a number like 123 like “one times hundred, two times ten, three times one” – when summed up it’s our number: 1×100 + 2×10 + 3×1.

And indeed, this does have a regularity in it, as the amount of symbols we have for a single digit determines how many numbers we can express. Premarket stock futures Every time we add a digit to a number, we have all the symbols available again for all previous digits, so the number of things doesn’t double, but increase by a power of the number of symbols.

For our three symbols system we can see that a single digit can express three combinations (3 1), two digits can express nine (3 2) and three digits can already express twenty-seven (3 3) combinations.

This holds true for any number system: Each digit adds one to the exponent while the base is the number of symbols the system has available. Convert us dollars to australian dollars The one weird trick to convert numbers to and from decimal:

Conveniently there’s one little trick that, with some practice, makes it easier to read numbers in any arbitrary system, using simple multiplication and addition.

To find the representation of a decimal number in any other base, you find the largest power of the base to fit into that number, which gives you the left-most digit of the other system, then you repeat that step for the rest until you are done.

The largest power of two that fits into 6 is 2 2=4. Binary stars list So you take a 1 and remember that this will be the left-most number of three digits (we haven’t checked if 2 1 and 2 0 fit into the rest yet).

6-4 gives us a rest of 2. Exchange rate for euro to dollar The largest power of two that fits into 2 is 2 1=2. Capital meaning in economics So we now have 1×2^2 + 1×2^1 and 6-4-2=0, i.e leaves no rest, so we know that 2 0 didn’t fit, which means our number in binary is 1×2^2 + 1×2^1 + 0x2^0 or simply 110 (binary).

Now that we have seen that number systems can use an arbitrary number of symbols to encode any natural number without much trouble and how we can convert between our familiar decimal system and systems with any other number of symbols, we can pick whatever system is convenient for working with different types of data and represent it in a way that is easiest for the task at hand.

For instance, as two hexadecimal digits neatly fit the data in a single byte, we may use a hex editor when looking at binary files when we wish to see the individual bytes.