# Number System in Python

Number system is basically the classification of all the possible numbers. A number system is used to represent numeric values. Every number system consist of some symbols which can be used to represent various numbers.

Binary number system (Base — 2) — 0,1
Octal number system (Base — 8) — 0,1,2,3,4,5,6,7
Decimal number system (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

Binary (bin) : — We can convert any number to Binary values. i.e., — 0 and 1. E.g., Binary value for 25 is “11001”. In python, it can be seen as “0b11001”. 0b represent type of value. “b” means binary.

We can use “bin” in python to pull binary information. bin is an inbuilt function in Python.

Octal (oct) : — We can convert any number to Octal values. i.e., — 0, 1, 2, 3, 4, 5, 6 and 7. E.g., Octal value for 25 is “31”. In python, it can be seen as “0o31”. 0o represent type of value. “o” means Octal.

We can use “oct” in python to pull Octal information. oct is an inbuilt function in Python.

Decimal (int and float) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 : — Any number available belongs to decimal value. decimal is always there with a value. Some values have numbers after decimal some have only 0.

Hexadecimal (hex) : — We can convert any number to hexadecimal values. i.e., — 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e and f. E.g., Hexadecimal value for 25 is “19”. In python, it can be seen as “0x19”. 0x represent type of value. “x” means Hexadecimal.

We know, numbers always lies between 0–9. Therefor, for Hexadecimal, we will use a, b, c, d, e and f instead of 10, 11, 12, 13, 14 and 15. Final count must be 16 for all values.

Now, the question is, how we can calculate it. And, how we can convert binary numbers to original numbers.

Lets take an example of binary. We will check remainder of any value by using only 2 as a base number. for octal, base value we need to take is 8, for decimal, it will be 10 and for hexadecimal, it will be 16.

Binary to number : — Let’s try to reset binary number for 25 to its decimal value. We use 2 as a base number (because we are working on Binary). We will start assigning power starting from 0 and we will go from right most value to the left, assigning 0, 1, 2 and so on till the end as a power. We will leave all those values, which are being represented as 0 in binary number. Once done with the same, just add all the numbers. Try the same with Hexadecimal and octal as well.

Working as a Data Scientist in UHG. Having experience in Machine Learning, Deep learning and Natural Language Processing (NLP).

## More from Sandeep Sharma

Working as a Data Scientist in UHG. Having experience in Machine Learning, Deep learning and Natural Language Processing (NLP).