Course Introduction to Programming
Numeral System
In this lesson, you will learn about Number Systems and the internal representation of a computer, getting to know the different number systems and how the positional system works.
We will also understand how to perform conversions to decimal and from decimal to other bases, in addition to understanding how the internal representation of information in the machine occurs.
Number system
A number system is a set of symbols and rules used to represent quantities. The key point of any system is its base, which defines the quantity of symbols available to form numbers. The value of a number, therefore, depends not only on the symbol we use, but also on the position it is in, since each position represents a power of the base.
Although the system we use in our daily lives is the decimal system (base 10), with its ten digits (0 to 9), other systems are essential, especially in computing. The main examples are:
- Binary (base 2): Uses only two symbols: 0 and 1. It is the fundamental system for computers, which understand information through electrical states of "on" and "off".
- Octal (base 8): Uses eight symbols, from 0 to 7.
- Hexadecimal (base 16): Employs 16 symbols: the digits 0 to 9 and the letters A to F. The letter A represents the value 10, B represents 11, and so on, up to F, which represents 15.
Familiarity with these systems, and the ability to convert between them, is crucial for anyone working with technology, programming, and other areas that depend on digital logic.
Positional system
The positional system is the foundation of our calculation. In it, each digit has a value that depends on its position in the number.
For example, in the decimal system the first digit of a number is the units, the second is the tens, the third is the hundreds, and so on, which is related to the number system.
The value of each number is equal to the digit in the first position multiplied by the base to the power of zero, plus the digit in the second position multiplied by the base to the power of one, and so on. This same logic applies to any base, just by replacing 10 with the base in question.
Conversion to the decimal system
To convert numbers from any base to decimal, simply apply the positional system, multiplying each digit by the power of the base corresponding to its position.
Some other examples of conversion to the 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 perform the process and practice with these examples. ๐
Conversion from the decimal system to other bases
To convert a number from the decimal base to any other base (binary, octal, hexadecimal, etc.), we use the successive division method. The process is simple: divide the number by the desired base, keep the remainder, and repeat the division with the quotient until it becomes zero. The sequence of remainders, read from bottom to top, is the result of the conversion.
Decimal to Binary (Base 2):
Example: Convert 46 to binary.
- 46 รท 2 = 23 remainder 0
- 23 รท 2 = 11 remainder 1
- 11 รท 2 = 5 remainder 1
- 5 รท 2 = 2 remainder 1
- 2 รท 2 = 1 remainder 0
- 1 รท 2 = 0 remainder 1
Answer: 4610 = 1011102
Decimal to Octal (Base 8):
Example: Convert 155 to octal
- 155 รท 8 = 19 remainder 3
- 19 รท 8 = 2 remainder 3
- 2 รท 8 = 0 remainder 2
Answer: 15510 = 2338
Decimal to Hexadecimal (Base 16):
Example: Convert 4587 to hexadecimal
- 4587 รท 16 = 286 remainder 11 (B)
- 286 รท 16 = 17 remainder 14 (E)
- 17 รท 16 = 1 remainder 1
- 1 รท 16 = 0 remainder 1
Answer: 458710 = 11EB16
โ> โ ๏ธ Remember that in the hexadecimal system, remainders from 10 to 15 are represented by the letters A to F.
Again, I suggest you try the conversion process to practice. ๐
Internal representation
A computer's memory is composed of a vast set of bits, the smallest unit of information in digital systems. A bit can only store two values: 0 or 1, which represent false and true, respectively. This means that, at its most fundamental level, any and all information stored on a computer, whether it's text, an image, a video, or a program, is just a long sequence of zeros and ones.
This is where the concepts of base conversion connect directly with the internal workings of the computer. The binary, octal, and hexadecimal systems are essential tools for programmers and engineers to read, understand, and manipulate these sequences of bits. In essence, base conversion is the foundation for communication between the machine's binary language and human language.
Conclusion
In this lesson, you learned what number systems are, how the positional system works, and how to perform conversions between decimal, binary, octal, and hexadecimal. We also saw that all information on a computer is represented by bits (0 and 1), and that knowing these bases is essential for understanding and working with digital data.
Now you know what number systems are, how to convert between some bases, and what the internal representation of a computer's memory is like. ๐
