- What is the Number System in PHP?
- How many types of Number System in PHP?
- What is the Binary Number System and Bit?
- What is Octal Number System?
- What is Decimal Number System?
- What is Hexa Decimal Number System?
- How can you convert decimal to Binary and binary to Decimal Number?
- How can you convert decimal to Octal and Octal to Decimal Number?
- How can you convert to decimal to Hexa Decimal and Hexa Decimal to Decimal Number?
- Have any different rules to write in PHP to Binary, Octal, Decimal, Hexadecimal numbers?

## What is the Number System on PHP?

The numbering system in PHP or any programming language is The way we used to show or represent the numbers in different groups based on different bases.

“4” Type Number System in PHP:

numbering system name | maximum number or base | allowed 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 the Binary Number System and the Bit?

Binary means two (2), that is, it is a numbering system that display all the numbers only with 0 and 1. So that there are two digits 0 and 1, call the Binary Numbering System. Those two numbers, 0 and 1, process all the information in the computer, solve mathematical problems, store data and perform all kinds of tasks. When we run and execute a program on a computer, the computer processes all commands in 0 and 1 and then execute them. The basic of the Binary Numbering System are two (2). Each number is called a bit in binary mode. Speaking of computers, find out why it isn’t a good idea to mine bitcoins using your PC through this USApr mining guide.

## What is the Octal Number System?

Octal means 8, it is a numbering system that display all numbers only from 0 to 7. Because of 0 to 7 of these eight digits are used, that’s why it’s call a Octal Numbering System. Its basically group binary numbers into three digits (eg, 000,001,010,011,100,101,110,111) processing different types of computer information, solving mathematical problems, storing information, or performing various tasks. The foundations of the Octal Numbering System are eight (8).

## What is Decimal Number System?

decimal means 10. It is a numbering system that display all numbers between 0 to 9. How ever 0,1,2,3,4,5,6,7,8,9 of 10 digits are used, this is called Decimal Numbering System. It basically processes various types of information in our daily life, solves the problem of arithmetic and performs various tasks. Decimal Numbering System base on ten (10).

## What is Hexadecimal Number System?

Hexa decimal means sixteen or 16, that means, it is a numbering system that displays all numbers only from 0 to 15. In this method, the sixteen numbers 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 0 to 15 of these 16 digits are called Hexadecimal Numbering System. This is basically the binary number of four different data groups (eg 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111) By performing tasks, solving mathematical problems, storing information and performing various tasks. The base of Hexadecimal Numbering System is ten (16).

## How decimals can convert binary and Binary to Decimal Number?

#### Rules of Convert Decimal Number to Binary Number:

- The number to be converted to binary should be divided by 2
- The Modulus will come 1 or 0 both will take.
- The result of divide will be divided by 2
- The Modulus will come 1 or 0 both will take.
- The result of divide will be divided by 2
- The Modulus will come 1 or 0 both will take.
- In this way the divide should be divided by 2 until it is divisible
- Once the batch is received 1, the number of binary numbers will be 1 and the bottom of all the segments along the bottom.

#### Example 1: 16 Convert to Binary

16 ÷2 = 8; Modulus 0

8 ÷2 = 4; Modulus 0

4 ÷2 = 2; Modulus 0

2 ÷2 = 1; Modulus 0

16 in binary number = 10000

#### Example 2: 17 Convert to Binary

- 17 ÷2 = 8; Remaining 1
- 8 ÷2 = 4; Remaining 0
- 4 ÷2 = 2; Remaining 0
- 2 ÷ 2 = 1; Remaining 0

17 of the Binary numbers = 10001

#### Convert From Binary Number to Decimal Number:

- Top two example, binary digit will count down to top. The bits left on the right side of the Binary Number must be multiplied by their local values.
- Then the multiplied number of digits added to the decimal number.

Example: 10001 will be convert 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 the decimal to the Octal and the Octal to Decimal Number?

- The number to be converted to Octal, will be divided by 8
- The Modulus will come 1 or 0 both will take.
- The result of divide will be divided by 8
- In this way, the result is until less then 8 should be divided by 8
- If the number of 7 or less , the Octal Number will be the last fraction and all the numbers from the bottom, together with the number formed.

#### Example 1: 139 Convert to Octal

139 ÷ 8 = Result 17 Modulus 3

17 ÷8 = Result 2 Modulus 1

139 The result of Octal number is 213

#### Convert From Octal Number to Decimal Number:

- The right-hand bits of the Octal Number should be multiplied by the local values of 8.
- Then the multiplied number of digits added to the decimal number.

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

Octal 213=(2*8^{2})+(1*8^{1})+(3*8^{0})=2*64+1*8+3*1

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

## How to convert the decimal to Hexadecimal and Hexadecimal to Decimal Number?

#### Rules of convert to Decimal Number to Hexadecimal Number:

- The number to be converted to Hexadecimal is to be divided by 16
- The Modulus will come 1 or 0 both will take.
- The result of divide will be divided by 16
- In this way, the result is until less then 16 should be divided by 16
- If the number obtained in any of the numbers 15 or less, the Octal Number will be the last fraction and all the numbers from the bottom to the top, together with the number formed. However, the next number of 0-9 will be placed in 10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F respectively.

#### Convert 1: 17 transfer to Hexadecimal

17 ÷16 = Result 1 : Modulus 1

17 of the hexadecimal numbers = 11

#### Convert From Hexadecimal Number to Decimal Number:

- The left sides of the hexadecimal number should be multiplied by the local values of 16.
- Then the number of digits added to the decimal number.

#### Example: 11 or C Hexadecimal Number convert to Decimal Number

Hexadecimal 11=B=(1*16^{1})+(1*16^{0})=1*16+1*1

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

## Is there a different rule in Binary, Octal, Decimal, Hexadecimal number in PHP?

Yes, every numbering system in PHP has different rules for writing. Notice the following table:

Number System Name | rules of writing | example |
---|---|---|

Binary | Before typing Binary Number in PHP, 0b (zero with b) is to be added and the number range is to be 0-1. | 0b01,0b10,0b11 |

Octal | Before typing the Octal Number in PHP, it is to add 0 (zero) and the number range is between 0-7. | 01, 02, 03, 04, 05, 06, 07 |

decimal | All the numbers in PHP 0-9 are counted as e Decimal Numbers. | 0,1,2,3,4,5,6,7,8,9 |

Hexadecimal | Before writing Hexadecimal Number in PHP, 0x (zero with x) is to be added and the number range is between 0-15. | 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:

<?php echo 11+011+0b11+0x11; // Output: 40; but why? ?>

**Explanation:** In the above example, notice that the first number 11 decimal then starting with 011 number 0 is the octal whose decimal value “(1 * 8 ^{ 1 }) + (1 * 8 ^{ 0 }) = 9 “9 then starting with 0b11 number 0b, this is the Binary whose decimal value is” (1 * 2 ^{ 1 }) + (1 * 2 ^{ 0 }) = 3 “3 Starting with the last 0x11 number 0x, this is the hexadecimal whose decimal value” (1 * 16 ^{ 1 }) + (1 * 16 ^{ 0 }) = 17 “17. So the result Stood (11 + 9 + 3 + 17 = 40)

Hi, My name is Masud Alam, love to work with Open Source Technologies, living in Dhaka, Bangladesh. I’m a Certified Engineer on ZEND PHP 5.3, I served my first five years a number of leadership positions at Winux Soft Ltd, SSL Wireless Ltd, Canadian International Development Agency (CIDA), World Vision, Care Bangladesh, Helen Keller, US AID and MAX Group where I worked on ERP software and web development., but now i’m a founder and CEO of TechBeeo Software Company Ltd. I’m also a Course Instructor of ZCPE PHP 7 Certification and professional web development course at w3programmers Training Institute – a leading Training Institute in the country.

Thank you sir, very informative articles

Awesome really fantastic,Thank you so much You provided such a useful and helpful information