Binary , Hexa , octa conversion in Python part 11
The decimal system is the most commonly used number system. But the computer only understands the binary. Binary, octal, and hexadecimal number systems are closely related and we may need to convert decimals to these systems. The decimal system is base 10 (ten symbols, 0–9, used to represent a number) and similarly, binary 2 is base, octal base is 8 and hexadecimal base is 16.
A number with the prefix '0b' is considered binary, '0o' is considered octal and '0x' is hexadecimal. for example:
60 = 0b11100 = 0o74 = 0x3c
source code
script.py
Ipathon shell
OutPut
The decimal value of 344 is:0b101011000 in binary.
0o530 in octave.
0x158 in hexadecimal.
Note: To test the program, change the value of dick in the program.
In this program, we have used the built-in functions bin (), oct () and hex () to convert a given decimal number to other number systems.
These functions take integers (in decimal) and return a string.
0 Comments