Course Introduction to Programming
Numeral System
In this class, you will learn about numeral systems and internal computer representation. You will learn topics such as:
- Numeral system;
- Positional system;
- Conversion to decimal;
- Conversion from decimal to binary;
- Internal representation.
Numeral system
A numeral system serves to represent quantities. The numeral system most used by us is the decimal, but a computer uses the binary system.
In the decimal base, the numbers are represented using 10 characters: 1, 2, 3, 4, 5, 6, 7, 8, 9 and 0. In the binary base, we use only 2 characters: 0 and 1.
The difference between numeral systems is how many characters are used to represent the numbers.
Although the decimal system is the most used by us, there are other types of numbering systems. We use the word base to refer to one system. For example:
- Decimal (base 10)
- Binary (base 2)
- Octal (base 8)
- Hexadecimal (base 16)
As an example, in the hexadecimal system we use the characters from 0 to 9; then, we use letters from A to F. In this case, A would be worth 10, B would be worth 11 and so on.
Positional system
The positional system is used to calculate the value of a certain numbering system, in which each character has a value associated to the position it is in.
For example, in the decimal system, the first digit of a number is the ones, the second is the tens, the third is the hundreds and so on, which is related to the numbering system.
Each number has the value equal to the first position multiplied by how many characters are being used to the zero power, plus the second position multiplied by how many characters are being used to the second power and so on.
Conversion to the decimal system
We can use the idea of the positional system to calculate the value on any other base, i.e. any other numeral system (note that the 2 under the
Some other examples of conversion to decimal base are:
- The value of
in decimal is 1809. - The value of
in decimal is 171. - The value of
in decimal is 55. - The value of
in decimal is 82. - The value of
in decimal is 29.
Feel free to do the process and practice with these examples. ๐
Converting from decimal to the binary system
To convert a number
Example: Convert 46 to binary.
46%2=0, 46/2=23
23%2=1, 23/2=11
11%2=1, 11/2=5
5%2=1, 5/2=2
2%2=0, 2/2=1
1%2=1, 1/2=0
Answer: 101110
It is important to remember that the percentage (%) symbol in programming is used to represent the module operation, i.e. the remainder of the division.
Some other examples of conversion from decimal to binary are:
- The value of 10 in binary is 1010.
- The value of 64 in binary is 1000000.
- The value of 63 in binary is 111111.
- The value of 55 in binary is 110111.
- The value of 39 in torque is 100111.
Again, I suggest you try the conversion process to practice. ๐
Internal representation
The computer memory is formed by a set of bits. A bit is a memory space in which only one type of information can be stored. Each bit can only store true (1) or false (0).
We can then conclude that all the information stored in the computer is just a set of zeros and ones. Therefore, the computer uses various methods to retrieve the information saved as zeros and ones and convert it into information that is presentable to the user.
You now know what numeral systems are, how to do the conversion between some bases and what the internal representation of the computer memory is like.