DEV Community

Aria
Aria

Posted on

Understanding Decimal, Binary, Hexadecimal, and Octal Numbers

There are many different bases and types of numbers in the fields of mathematics and computer science. Decimal, binary, hexadecimal, and octal are four of the most widely used number systems. The fundamentals of each of these number systems, their transitions, and the functioning of mathematical operations like addition, subtraction, multiplication, and division in the decimal system will all be covered in this blog post.

Decimal Numbers

Decimal numbers are the numbers we use in our everyday lives. They are base 10 numbers, which means they use ten symbols (0-9) to represent values. For example, the number 256

Binary Numbers

Binary numbers, on the other hand, are base 2 numbers. They use only two symbols, 0 and 1. Binary is the language of computers, with each digit representing a power of 2. For instance, the binary number 1010 is equal to 18 + 04 + 12 + 01 in decimal.

Hexadecimal Numbers

Hexadecimal numbers are base 16 numbers and use 16 symbols: 0-9 and A-F (representing 10-15). Hexadecimal is often used in programming to represent large binary numbers more concisely.

Octal Numbers

Octal numbers are base 8 numbers and use 8 symbols: 0-7. They were more popular in the past of computing, but now they are mostly replaced by hexadecimal.

Transition between Number Systems

In the field of computing, converting between various number systems is crucial. Here is a quick explanation of how to change between them:

Decimal to Binary: Divide the decimal number by 2 repeatedly, recording remainders, until the quotient is 0. The remainders, read from bottom to top, form the binary representation.

Decimal to Hexadecimal: Similar to binary conversion, but divide by 16 instead of 2. Use A for 10, B for 11, and so on for values 10-15.

Decimal to Octal: Divide by 8 instead of 2 or 16.

Arithmetic Operations in Binary, Hexadecimal, and Octal

  • Addition: In binary, addition involves summing corresponding place values from right to left, carrying over when the sum exceeds 1. In hexadecimal and octal, addition proceeds similarly, with carryovers occurring when values surpass the base. For example, in hexadecimal, carrying over occurs when the sum exceeds 15 (F in hexadecimal).

  • Subtraction: Subtraction in binary is a process that involves careful borrowing when the number being subtracted from is smaller than the number being subtracted at any position. The same applies to hexadecimal and octal, which are number systems that use 16 and 8 symbols respectively.

  • Multiplication: The same method of long multiplication that is used in the decimal system can be used in these systems as well, but the multiplication tables are different depending on the base of the system.

  • Division: The long division algorithm is used to do division in different bases, such as binary, octal, or hexadecimal. This algorithm produces both a quotient and a remainder, which are changed according to the base of the system.

Representing Negative Numbers in Binary

Positive integers are easy to represent in the binary number system. But negative numbers need special attention. The most common way to represent negative numbers in binary is using Two’s Complement notation. This method allows for effective arithmetic operations with both positive and negative integers.

Two's Complement Notation:
To show a negative number, Two’s Complement notation changes the sign bit (the bit on the left). In a normal binary representation, the bit on the left is the most significant bit (MSB) and is usually used as the sign bit. The number is positive if it’s 0; the number is negative if it’s 1.

In conclusion, binary, hexadecimal, and octal numerical systems are very important in mathematics and computer science. They are essential skills for those who work with numerical computation, especially in the field of computing. They need to know how to switch between these systems and how to do basic arithmetic operations within their rules.

Top comments (0)