Octal Number System
Octal Number System is one in which the base value is 8. It uses 8 digits i.e. 0-7 for the creation of Octal Numbers. It is also a positional system i.e weight is assigned to each position.
1) Octal to Binary:
Octal numbers are converted to binary numbers by replacing each octal digit with a three-bit binary number. In python bin( ) function is used to convert octal number to binary number. The value is written with ‘0o’ as a prefix which indicates that the value is in the octal form.
eg. (123)8 = (001 010 011)2 = (1010011)2
O = 0o123
print("Octal to Binary",O,":",bin(O))
Output:
Octal to Binary 0o123 : 0b1010011
2) Octal to Decimal:
An octal number can be converted into a decimal number by assigning weight to each position. In python int( ) function is used to convert octal to decimal numbers. Two arguments are get passed, the first is a string of octal numbers, and the second is the base of the number system specified in the string.
(342)8 = 3* 82 + 4*81 + 2*80
= 3*64 + 4*8 + 2*1
= 226
(342)8 = (226)10
b = "342"
print("Octal to Decimal",b,":",int(b,8))
Output:
Octal to Decimal 342 : 226
3) Octal to Hexadecimal:
An Octal number can be converted into a hexadecimal number by converting the number into a decimal and then a decimal number to hexadecimal. In python hex( ) function is used to convert octal to hexadecimal numbers.
Let’s first convert b into a decimal number.
b = (456)8
(456)8 = 4*82 + 5*81+ 6*80
(456)8 = (302)10 = (12E)16
h = 0o456
print("Octal to Hexadecimal", h,":", hex(h))
Output:
Octal to Hexadecimal 302 : 0x12e
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)