Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Binary numbers

Peter Tillema edited this page Sep 15, 2018 · 2 revisions

This subsection covers the binary number system, so if you already know how that works, feel free to skip this section. If you plan on using the more advanced features of ICE, such as bitwise operators (covered below), you'll need to have an understanding of how numbers are stored in computers as bytes and bits of binary.

In our standard decimal number system, there are ten different characters, zero through nine. When we put multiple of these characters together into one number, the order of these numbers from right to left signifies how big each place is, going by powers of ten starting at zero. For example, in the number 5124, the farthest right number (number 4) is the smallest, having only ten to the power of zero amounts per value. If you look at the character to the left (number 2), you now have a value that has ten to the power of one, amounts. Look left again (number 1), and you have ten to the power of two amounts. This means that the amount, 5124, is compromised of 4 amounts of one (10^0), 2 amounts of ten (10^1), 1 amount of a hundred (10^2), and 5 amounts of a thousand (10^3). To get the amount for each place, you take the amount of characters in the number system, ten for decimal, and power it to the place the character is in going from the right.

In binary, however, there is only ones and zeroes, so only two characters. That means that each place in a binary number is an amount of a power of two. Take the following number for example: 001101. Now let's convert it into decimal so we can actually understand what value that number represents. Starting from the right-most place, 1 (the digit in the place) times 2^0 (the amount of the place) gives us 1. Now we continue to the left. In the second place from the right, we have a 0, which means no value, so we can ignore this and continue to the left. In the third place we have a 1, so we multiply 1 by 2^2 (power of two because this is the second place after the right-most place). 1 times 4 is 4, and we add the previous values, 1+4 = 5. Look left once more and we have another 1, so we multiply 1 by 2^3 (power of three because this is the third place after the right-most place). 1*8 = 8, and we add the previous values, 5+8 = 13. The rest of the numbers to the left are zeroes, so we ignore them. After that tedious process, we have 13. So binary 001101 is equal to decimal 13.

Clone this wiki locally