Introduction
The binary system is the basis for the operation of computers and digital electronics and is a system that uses only two digits: 0 and 1. Each digit in a binary number is called a “bit” , and eight bits represent a “byte”
Each bit in a binary number represents some power of two. If we have a four-digit binary number, then the rightmost digit represents the so-called “Least Significant bit” and its exponent is “0” so its degree is 2^0, moving to the left the exponent of two increases by one, so the second bit is 2^1, the exponent of the third bit is 2 ie. 2^2 and the fourth bit is 3, i.e. 2^3. Moving “to the left” each subsequent bit is “more significant” so the last bit is called the “Most Significant bit”.
Converting binary to decimal system
In the binary system, the base is not “10” but “2”, so the binary number “1001” would have the next decimal value of the number 9. Here’s how we get there:
1*2^3 + 0*2^2 + 0*2^1 + 1*2^0 = 8 + 0 + 0 + 1 = 9
DECIMAL SYSTEM:
In the decimal system, each digit in the binary number represents a degree of the number 10. And if we have a decimal number of four digits, then the rightmost digit has the exponent “0”, so its degree is 10^0, moving to the left the exponent increases by one, so the second digit is 10^1, the exponent of the third digit is 2, i.e. 10^2, and the fourth digit is 3, i.e. 10^3. To get the value of a decimal number, it is necessary to add up all the values. For example the number “583” has the following value:
1: 5*10^2 + 8*10^1 + 3*10^0 = 500 +80 +3 = 583
Formats for organizing bytes
When multibyte data (such as integers greater than 255) are stored in memory they can be stored in different bit orders. There are two methods for organizing the bytes of binary data: “Big Endian” and “Little Endian”.
In Big Endian format, the most significant byte (MSB) is placed at the lowest (first) memory address. In contrast, the Little Endian format places the least significant byte (LSB) at the lowest (first) address. These formats have a direct impact on the way computers read, write, and manipulate multibyte binary values. In the context of computer architecture and network protocols, the “big endian” format is often considered the standard representation of data. On the other hand, the “little endian” format is often used in some computer architectures, including most versions of Intel x86 and x86-64 processors.
Example
For 32-bit data, the binary representation would be:
- “Big Endian” (read from left to right so the largest byte is on the left and the smallest on the right):
0001 0010 0011 0100 0101 0110 0111 1000 - “Little Endian” (reads from right to left, so the largest byte is on the right and the smallest on the left) so to represent the same binary number we have to reverse the order:
1000 0111 0110 0101 0100 0011 0010 0001
NOTE:
In reality, when dealing with true 8-bit bytes, little endian order means to reverse the order of bytes within a larger data type (such as a 32-bit integer), not the bits within a byte. In this context, for explanatory purposes we have assumed that each group of 4 bits is an independent unit.

Binary representation of decimal numbers
Binary Representation of Negative Numbers
In computing, there are several methods for representing negative numbers in binary. The two main methods are: “Complement one” , “Complement two”. Complement is the addition of a given number to some predefined value, most often it is realized by adding the number to the largest number of the binary system or to the basis of the S number system.
METHODS FOR REPRESENTING NEGATIVE NUMBERS:
1) “One’s Complement” (Ones’ Complement)
In the one’s complement method,negative numbers are represented by inverting all bits of the positive value of the number. It has two representations for zero: 00000000 and 11111111.
2) “Two’s Complement” (Two’s Complement)
“Two’s complement” is the most commonly used method for representing negative numbers. This method uses the first bit to indicate the sign, where 0 indicates a positive number and 1 a negative number. To get a negative number, we invert all the bits of the positive number and add 1 to the result.
Example of converting the number “-5” to binary (“One’s complement”)
For -5, we first write the 5 as 00000101 in binary, then invert all the bits to get 11111010 as the “one’s complement” representation of -5.
Example of converting the number “-5” to binary (“Two’s complement”)
To convert the negative integer number -5 to binary using the Two’s Complement method, follow these steps:
- Let’s convert the absolute value of the number (5) into binary form, which is 101.
- Append the number with zeros to the desired number of bits, for example 8 bits, to get 00000101.
- We invert all the bits, which gives 11111010.
- We add 1 to this number, getting 11111011, which is the “Two’s Complement” representation of the number -5.
This binary number in the “Two’s Complement” method can be “read” in reverse to return to the original decimal number -5.
Each of these methods has its advantages and disadvantages. “”Two’s complement”” is most commonly used because of its efficiency in arithmetic operations and its unique representation of zero.
Converting an integer to binary
To convert a decimal number to binary, you can use the divide by 2 method. This procedure involves dividing the decimal number by 2 and writing down the remainder. The remainders will represent the digits of the binary number, and the process is repeated with each quotient obtained by division until the quotient becomes 0. It is important to remember that the binary number is read from the last remainder to the first, that is, in the reverse order of how they were written.
We can get the display of decimal numbers in binary format if we follow the following steps:
- Let’s determine the sign of the number. 0 for positive, 1 for negative.
- Let’s convert the integer part of the number to binary format.
- Multiply the decimal part of the number by 2.
- Record the integer part of the result as a binary digit (0 or 1).
- Take the remaining decimal part of the result and repeat the process of multiplying by 2.
- Keep repeating the process until you get a result with no decimal remainder or until you reach the desired number of decimals.
Example of converting the number “13” to binary
- 13 divided by 2 is 6 remainder 1.
- 6 divided by 2 is 3 remainder 0.
- 3 divided by 2 is 1 remainder 1.
- 1 divided by 2 is 0 remainder 1.
When we record the remainders from bottom to top, we get the binary number 1101. So the decimal number 13 is in the binary system 1101.
When converting negative decimal numbers to binary format, ambiguous complement is often used and we will use it here. The procedure is as follows
- Converting the absolute value of a number to binary format: using the divide by 2 method.
- Inverting a digit: After obtaining the binary representation of the absolute value, invert the digits of the binary number by replacing all zeros with ones and all ones with zeros.
- Add 1: Add 1 to the inverted binary number. The result of this step is the ambiguous complement of the original negative decimal number, which is its binary equivalent.
Example of converting the number “-13” to binary
If we use an 8-bit system for -13, the procedure would be:
- Convert 13 to binary:
00001101. - Invert all digits:
11110010. - Add 1:
11110011.
So -13 in 8-bitto the ambiguous complement is 11110011.
Converting a decimal number with a fraction
The whole part of the number is converted in the previously mentioned way, but to convert a decimal number with a fraction to binary, you can use the method of multiplying by 2. This procedure involves multiplying the decimal number by 2 and writing down the whole part. The whole part will represent the digits of the binary number, and the process is repeated with the decimal part until we get the desired number of decimals or until we get a result without a decimal remainder.
Example of converting the number “13.75” to binary
The integer part of the number 13 is converted to binary in the same way as any whole number. The process of dividing by 2 gives the binary equivalent of 1101.
The fractional part 0.75 is converted by multiplying by 2:
- 0.75 × 2 = 1.5 (note 1, continue with the fractional part 0.5)
- 0.5 × 2 = 1.0 (note 1, the fractional part is now 0)
This gives the fractional binary equivalent of .11, making the entire binary representation of 13.75 1101.11.
Therefore, the binary equivalent of the decimal number 13.75 is 1101.11.
Example of converting the number “0.625” to binary
To convert the decimal number 0.625 to binary, we follow the steps above:
- Multiply by 2: 0.625 x 2 = 1.25. The whole digit is 1, so the first binary digit is 1.
- Repeat with the remainder: We take the decimal part of 0.25 and multiply by 2 again.
- Multiply by 2: 0.25 x 2 = 0.5. The whole digit is 0, so the second binary digit is 0.
- Multiply by 2: 0.5 x 2 = 1.0. The whole digit is 1, so the third binary digit is 1.
So 0.625 in decimal is .101 in binary.
This method can lead to a situation where the iteration process never completes if a decimal number that does not have an exact equivalent in binary is being converted. In such cases, an approximation to a certain number of decimal places is usually used.
Example of converting the number “5.5” to binary
Converting the decimal number 5.5 to binary format:
- The integer part (5) is 101 in binary.
- The part after the decimal point (0.5) is 0.1 in binary.
- By combining we get 101.1.
- In IEEE 754 format, this would be normalized with a certain exponent (depending on precision and format).
Example of converting the number “-2.75” to binary
To convert -2.75 to binary:
- The sign is 1 because the number is negative.
- The integer part (-2) is 10 in binary.
- The decimal part (0.75) is converted to 0.11 in binary.
- By combining the integer and decimal parts, we get the binary number 10.11.
Binary representation of hexadecimal data
The hexadecimal number system uses 16 symbols (0-9 and A-F). In this system, numbers are written using the digits 0 through 9 and the letters A through F, where A represents 10, B is 11, C is 12, D is 13, E is 14, and F is 15 in the decimal system. The hexadecimal number system uses base 16, and similarly to binary and decimal numbers, the number 456 actually has a value of 4*16^2+5*16^1+6*16^0= 1110 in the decimal system. For example, the hexadecimal number FF represents the binary number 11111111 or the decimal number 255 (15*16^1+15*16^0=255).
Hexadecimal numbers are very similar to decimal e.g. 456 is such a number, in order to distinguish it from decimals, they are marked as follows: 0x456 where “0x” does not change the value but only represents an indicator.
Hexadecimal numbers are useful in programming because they provide a simpler way to represent binary numbers.Hexadecimal numbers are convenient for representing binary numbers because each hexadecimal digit corresponds to four binary bits. To convert a hexadecimal numberto binary, we convert each hexadecimal digit separately to the corresponding four-bit binary number.
| Hexadecimal | Binary |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
| A | 1010 |
| B | 1011 |
| C | 1100 |
| D | 1101 |
| E | 1110 |
| F | 1111 |
Example of converting the hexadecimal number “0x1A3” to binary
To convert the hexadecimal number 1A3 into binary we will use the previous table:
- Convert 1 to binary: 0001
- Convert A to binary: 1010
- Convert 3 to binary: 0011
So the hexadecimal number 1A3 in binary is 000110100011.
Binary representation of strings
Converting strings (text) to binary is usually done using standard character encoding schemes, where each character has its own binary value. Character Encoding is a system that maps sets of binary numbers to characters (letters, numbers, symbols), allowing us to use computers to store and display text. The most famous encoding is ASCII, but it has a limited character set. UTF-8 is a more widely used encoding that can represent a much larger number of characters, including everything needed for almost all of the world’s languages. ASCII can directly represent characters like ‘A’ (65) or ‘a’ (97), while UTF-8 can represent more complex characters like ‘ć’ (in two or more bytes).
ASCII Character Encoding
ASCII is a system that uses 7 bits to represent each character, allowing 128 different symbols. For example, the capital letter “A” is represented by the number 65 in the decimal system, or `01000001` in the binary system.
Table of the first 10 Letters of the Alphabet with Decimal, Hexadecimal and Binary Values
Example (ASCII)
For the string “Hi”:
- “H” in ASCII is 72, binary:
01001000 - “i” in ASCII is 105, binary:
01101001
Therefore, “Hi” becomes 01001000 01101001 in binary format.
UTF-8 Character Encoding
UTF-8 can use between 1 and 4 bytes to represent a character, supporting a much larger number of symbols, including different language scripts and emoji. UTF-8 is compatible with ASCII for the first set of 128 characters.
Note: There is no specific “table” for each string. Instead, use the relevant encoding tables to convert the character to binary. These codes enable the standardized conversion of textual data into binary sequences.
