- What is Number System in PHP?
- How many types of Number System in PHP?
- What is Binary Number System and Bit?
- What is Octal Number System?
- What is Decimal Number System?
- What is Hexa Decimal Number System?
- How to convert Decimal to Binary and Binary to Decimal Number?
- How to convert Decimal to Octal and Octal to Decimal Number?
- How to convert Decimal to Hexa Decimal and Hexa Decimal to Decimal Number?
- Is there any different rule for writing Binary, Octal, Decimal, Hexadecimal number in PHP?

**What is Number System in PHP?**

Numbering system in PHP or any programming language is a way to show or represent our daily used numbers by dividing them into different groups based on the maximum number or base and approved numbers.

**How many types of Numbering System in PHP?**

Number System 4 types in PHP:

Numbering System Name | Maximum Number or Base | Authorized Numbers |

Binary | Base 2 | 0,1 |

Octal | Base 8 | 0,1,2,3,4,5,6,7 |

Decimal | Base 10 | 0,1,2,3,4,5,6,7,8,9 |

Hexadecimal | Base 16 | 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F (A=10, B=11, C=12, D=13, E=14, F=15) |

**What is Binary Number System and Bit?**

Binary means two (2), meaning it is a numbering system in which all the numbers are expressed with only 0 and 1. All in all, since 0 and 1 are the two digits used in it, it is called Binary Numbering System. Using these two numbers i.e. 0 and 1, the computer processes all the information, solves mathematical problems, stores the information i.e. performs all kinds of tasks.

When we write and execute a program on a computer, the computer processes all the commands by converting them to 0 and 1. Binary Numbering System has two bases (2). In binary system each number is called a bit.

**What is Octal Number System?**

Octal means octave or 8, meaning it is a numbering system in which all numbers are expressed with only 0 to 7. All in all, since it uses these eight digits from 0 to 7, it is called Octal Numbering System. It basically groups binary numbers into three digits (eg: 000,001,010,011,100,101,110,111) to process different types of data on the computer, solve mathematical problems, store data, that is, perform various tasks. The basis of Octal Numbering System is eight (8).

**What is Decimal Number System?**

Decimal means decimal or 10, meaning it is a Numbering System in which all Numbers are expressed with only 0 to 9. All in all, since it uses these 10 digits 0,1,2,3,4,5,6,7,8,9 it is called Decimal Numbering System. It basically processes different types of information in our daily life, solves mathematical problems i.e. performs different tasks. The basis of decimal numbering system is ten (10).

**What is Hexadecimal Number System?**

Hexa Decimal means sixteen or 16, meaning it is a numbering system in which all numbers are expressed with only 0 to 15. The sixteen numbers in this method are 0,1,2,3,4,5,6,7,8,9 and 10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F , Since it uses these 16 digits from 0 to 15, so it is called Hexadecimal Numbering System.

It basically binary numbers are grouped into four digits (eg: 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111). Performs, performs mathematical problems, stores information, that is, performs various tasks. The basis of Hexadecimal Numbering System is ten (18).

**How to convert Decimal to Binary and Binary to Decimal Number?**

Rules for Converting Decimal Numbers to Binary Numbers:

- The number to be converted to binary must be divided by 2
- You have to take whatever is left over, if it is 0 you have to take it
- The quotient that will come will have to be divided again by 2
- You have to take whatever is left over, if it is 0 you have to take it
- The quotient that will come will have to be divided again by 2
- You have to take whatever is left over, if it is 0 you have to take it
- Thus the quotient has to be divided by 2 until it comes to 1
- If you get the quotient 1, the binary number will be 1 and all the
- divisions from bottom to top will be a number sitting side by side.

**Example 1: Convert 16 to Binary**

16 ÷ 2 = 8; The remainder is 0

8 ÷ 2 = 4; The remainder is 0

4 ÷ 2 = 2; The remainder is 0

2 ÷ 2 = 1; The remainder is 0

In the case of 16 the binary number = 10000

**Example 2: Converting 17 to Binary**

17 ÷ 2 = 8; Quotient 1

8 ÷ 2 = 4; The remainder is 0

4 ÷ 2 = 2; The remainder is 0

2 ÷ 2 = 1; The remainder is 0

**Binary number in case of 17 = 10001**

Conversion from Binary Number to Decimal Number

The bits to the left of the binary number on the right have to be multiplied by their local values.

Then the product of the product is the decimal number.

**Example: Convert 10001 to Decimal Number**

1 × 1 = 1

0 × 2 = 0

0 × 4 = 0

0 × 8 = 0

1 × 16 = 16

Decimal Number = 1 + 0 + 0 + 0 + 16 = 17

**How to convert Decimal to Octal and Octal to Decimal Number?**

**Rules for Converting Decimal Number to Octal Number:**

- The number to be converted to Octal must be divided by 8
- You have to take what will be the remainder, if it is 0, you have to take it
- The quotient will be divided by 8 again
- Thus the remainder should be divided by 8 until any number of 7 or less is expected
- If the quotient gets any number of 7 or less, the Octal Numbers will be the last quotient and all the quotations from bottom to top will be sitting side by side.

**Example 1: Convert 139 to Octal**

139 ÷ 8 = 17; Quotient 3

17 ÷ 8 = 2; Quotient 1

Octal number in case of 139 = 213

**Conversion from Octal Number to Decimal Number**

The bits on the left side of the Octal Number have to be multiplied by the local value of 8.

Then the product of the product is the decimal number.

**Example: Convert 213 Octal Number to Decimal Number**

Octal 213 = (2 * 82) + (1 * 81) + (3 * 80) = 2 * 64 + 1 * 8 + 3 * 1

Octal Number: 213 = 128 + 8 + 3 = 139 Decimal

**How to convert Decimal to Hexadecimal and Hexadecimal to Decimal Number?**

Rules for Converting Decimal Numbers to Hexadecimal Numbers:

- The number to be converted to Hexadecimal must be divided by 16
- You have to take what will be the remainder, if it is 0, you have to take it
- The quotient will have to be divided again by 16
- Thus the remainder should be divided by 8 until any number of 15 or less is expected
- If the quotient gets any number of 15 or less, the Octal Numbers will be the last quotient and all the fractions from bottom to top will be formed sitting side by side. However, the numbers after 0-9 should be 10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F respectively.

**Example 1: Converts 17 to Hexadecimal**

17 ÷ 16 = 1; Quotient 1

Hexadecimal number in case of 17 = 11

**Conversion from Hexadecimal Number to Decimal Number**

The bits on the left side of the Hexadecimal Number must be multiplied by the local value of 16.

Then the product of the product is the decimal number.

**Example: Convert 11 or C Hexadecimal Number to Decimal Number**

Hexadecimal 11 = B = (1 * 161) + (1 * 160) = 1 * 16 + 1 * 1

Hexadecimal Number: 11 = B = 16 + 1 = 17 Decimal

**Is there any different rule for writing Binary, Octal, Decimal, Hexadecimal number in PHP?**

Yes, PHP has different rules for each e-numbering system. Notice the table below:

Number System | Name Writing Rules | Example |

Binary | Before writing Binary Number in PHP, you have to add 0b (zero with b) and number range is 0-1. | 0b01,0b10,0b11 |

Octal | Before writing Octal Number in PHP, you have to add 0 (zero) and the number range has to be between 0-7. | 01, 02, 03, 04, 05, 06, 07 |

Decimal | In PHP, all numbers between 0-9 are considered as Decimal Numbers. | 0,1,2,3,4,5,6,7,8,9 |

Hexadecimal | In Pop: All Numbers Beethoven 0-9 Or Considered S Decimal Numbers. | 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF (A=10, B=11, C=12, D=13, E=14, F=15) |

**An example:**

**Explanation:** Notice in the example above, the first number is 11 Decimal then 011 number starts with 0 because Octal whose decimal value is “(1 * 81) + (1 * 80) = 9 ″ 9 then 0b11 number starts with 0b. Binary whose Decimal value is “(1 * 21) + (1 * 20) = 3 ″ 3 The last 0x11 number starts with 0x so it is Hexadecimal whose Decimal value is“ (1 * 161) + (1 * 160) = 17 ″ 17. So the result is (11 + 9 + 3 + 17 = 40)