Oct () function in python
oct() function in Python: oct() function is an important function in Python . It transforms any data type into the octal form. If anyone wants to convert any data from any format to octal form then it can be done easily with the help of oct() function.
Format:- oct(data), data is in int format.
Parameters:- inside the oct function we have to only pass the integer data.
Diagrammatic representation of oct function:-
Implementation of oct function in Python
Decimal to octal:-
Here, we take a decimal number as input and print that number in the octal form.
Binary to octal:-
Here, we take a binary number as input and print that number in the octal form.
Hexadecimal to octal:-
Here, we take a hexadecimal number as input and print that number in octal form.
Output:-
10 the number 10 in octal form is 0o12 11010011 the number 211 in octal form is 0o323 FFFF the number 65535 in octal form is 0o177777
Here first we take a decimal number 10 as input and print its octal form.
Next, we take a binary number 11010011 as input and print its octal form.
After that, we take a hexadecimal number FFFF as input and print its octal form.
Comments
Post a Comment