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  
Python3
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
Python3
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
Python3
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)

Similar Reads

Binary Number System

A number system with base or radix 2 is known as a binary number system. Only 0 and 1 are used to represent numbers in this system....

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....

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....

Hexadecimal Number System

A number system with a base of 16 is called a hexadecimal number system. It is represented using numbers between 0 to 9 and the alphabets between A to F. As both numeric digits and alphabets are used in this system, it is also called an alphanumeric system....