Decimal Number System
A number system with a base value of 10 is termed a Decimal number system. and it is represented using digits between (0 to 9). Here, the place value is termed from right to left as first place value called units, second to the left as Tens, so on Hundreds, Thousands, etc.
1) Decimal to Binary.
For decimal to binary conversion, the number is divided by 2 until we get 1 or 0 as the final remainder. In python bin( ) function is used to convert decimal to binary numbers.
Here, a = 10
(10)10 = (1010)2
# Decimal to Binary
a = 10
print("Decimal to Binary ", a, ":", bin(a))
Output:
Decimal to Binary 10 : 0b1010
2) Decimal to Octal
For Decimal to Octal conversion, the number is divided by 8 until we get a number between 0 to 7 as the final remainder. In python oct( ) function is used to convert decimal to octal numbers.
so, (10)10 = (12)8
# Decimal to Octal
a = 10
print("Decimal to Octal",a,":",oct(a))
Output:
Decimal to Octal 10 : 0o12
3) Decimal to Hexadecimal
For decimal to hexadecimal conversion, the number is divided by 16 until we get a number between 0 to 9 and (A to F)as the remainder. In python hex( ) function is used to convert decimal to hexadecimal numbers.
so, (1254)10 = (4E6)16
a = 1254
print("Decimal to Hexadecimal",a,":",hex(1254))
Output:
Decimal to Hexadecimal 1254 : 0x4e6
Number System in Python
The arithmetic value that is used for representing the quantity and used in making calculations is defined as NUMBERS. The writing system for denoting numbers logically using digits or symbols is defined as a Number system. Number System is a system that defines numbers in different ways to represent numbers in different forms.
Types of Number System
The number system in Python is represented using the following four systems:
- Binary Number System (base or radix =2)
- Octal Number System (base or radix = 8)
- Decimal Number System (base or radix = 10)
- Hexadecimal Number System (base or radix = 16)