This article is about Octal and Hexadecimal Numbering in PLC System.

Read Also Previous Articles if you did not read before.

- Lecture 1: What is Programmable Logic Controller in PLC?
- Lecture 2: PLC Hardware Components – PC Information
- Lecture 3: PLC Internal Architecture and Diagram Explanation
- Lecture 4: What is PLC System? and Working Principle
- Lecture 5: How to Connect Input Devices to PLC? Input Devices Examples
- Lecture 6: How to Connect Output Devices to PLC? PLC Output Devices
- Lecture 7: PLC Applications Examples And Solutions
- Lecture 8: Numbering System in PLC (Digital System)
- Lecture 9: The Binary System Concept in PLC

## Octal and Hexadecimal Numbering in PLC System

Binary numbers can become lengthy and difficult to handle, especially for larger values. To mitigate this issue, octal and hexadecimal numbering systems are often used as intermediaries between binary and decimal numbers in computer systems and industrial controllers.

The octal number system is a base-8 system, using digits from 0 to 7. Each digit in an octal number represents three bits. Octal numbers are convenient for representing groups of three binary digits because 2^3 equals 8. Octal numbers are often used in computer systems for addressing and other purposes.

The hexadecimal number system is a base-16 system, using digits from 0 to 9 and letters from A to F to represent values from 10 to 15. Each digit in a hexadecimal number represents four bits, allowing for more compact representation compared to binary or octal. Hexadecimal numbers are commonly used in programming and computer systems for various purposes, such as memory addressing, byte representation, and bitwise operations.

Converting between binary and octal/hexadecimal is straightforward. Octal numbers are grouped in sets of three bits, and each group can be converted to its corresponding octal digit. Similarly, hexadecimal numbers are grouped in sets of four bits, and each group can be converted to its corresponding hexadecimal digit.

Using octal or hexadecimal representation can make numbers easier to read, write, and manipulate compared to binary, while still maintaining a direct correspondence to binary representations used internally in computers.

In Allen-Bradley PLCs and many other computer systems, octal numbering is commonly used for input and output addresses to provide a more manageable and human-readable format compared to binary.

### Octal Number System

To convert denary (decimal) numbers to octal:

- Divide the denary number by 8.
- Write down the remainder as the rightmost digit of the octal number.
- Repeat steps 1 and 2 with the quotient obtained in the previous division until the quotient becomes 0.
- The octal number is obtained by writing the remainders in reverse order, from bottom to top.

Example: Convert the denary number 15 to octal:

15 ÷ 8 = 1 remainder 7

1 ÷ 8 = 0 remainder 1

The octal representation of 15 is 17.

To convert octal numbers to denary (decimal):

- Multiply each digit of the octal number by the appropriate power of 8 based on its position, starting from the rightmost digit.
- Sum up the results to obtain the denary value.

Example: Convert the octal number 365 to denary:

3 * 8^2 + 6 * 8^1 + 5 * 8^0 = 245

The denary representation of 365 is 245.

To convert binary numbers to octal:

- Group the binary digits into sets of three, starting from the leftmost digit.
- If the leftmost group has fewer than three digits, add leading zeros to make it a complete group.
- Replace each group with its corresponding octal digit.

Example: Convert the binary number 11010110 to octal:

11 010 110

The octal representation of 11010110 is 326.

To convert octal numbers to binary:

- Convert each octal digit to its 3-bit binary equivalent.

Example: Convert the octal number 21 to binary:

2 -> 010

1 -> 001

The binary representation of 21 is 010001.

I hope this clears up any confusion. Let me know if you have any further questions!

### Hexadecimal System

The hexadecimal system (hex) is based on 16 digits/symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. When a number is represented in this system, the digit position indicates the weight attached to each digit, increasing by a factor of 16 as we move from right to left.

To convert denary (decimal) numbers to hexadecimal:

- Divide the denary number by 16.
- Write down the remainder as the rightmost digit of the hexadecimal number.
- Repeat steps 1 and 2 with the quotient obtained in the previous division until the quotient becomes 0.
- If the remainder is greater than 9, replace it with the corresponding hexadecimal letter (A for 10, B for 11, C for 12, D for 13, E for 14, F for 15).
- The hexadecimal number is obtained by writing the remainders in reverse order, from bottom to top.

Example: Convert the denary number 156 to hexadecimal:

156 ÷ 16 = 9 remainder 12 (C)

9 ÷ 16 = 0 remainder 9

The hexadecimal representation of 156 is 9C.

To convert hexadecimal numbers to denary:

- Multiply each digit of the hexadecimal number by the appropriate power of 16 based on its position, starting from the rightmost digit.
- If a digit represents a letter (A to F), replace it with its corresponding denary value (A = 10, B = 11, C = 12, D = 13, E = 14, F = 15).
- Sum up the results to obtain the denary value.

Example: Convert the hexadecimal number 12 to denary:

1 * 16^1 + 2 * 16^0 = 18

The denary representation of 12 is 18.

To convert binary numbers to hexadecimal:

- Group the binary digits into sets of four, starting from the leftmost digit.
- If the leftmost group has fewer than four digits, add leading zeros to make it a complete group.
- Replace each group with its corresponding hexadecimal digit.

Example: Convert the binary number 1110100110 to hexadecimal:

11 1010 0110

The hexadecimal representation of 1110100110 is 3A6.

To convert hexadecimal numbers to binary:

- Convert each hexadecimal digit to its 4-bit binary equivalent.

Example: Convert the hexadecimal number 1D to binary:

1 -> 0001

D -> 1101

The binary representation of 1D is 00011101.

I hope this clarifies the conversion process. Let me know if you have any more questions!