Given a number in decimal number convert it into binary, octal and hexadecimal number. Here is function to convert decimal to binary, decimal to octal and decimal to hexadecimal.
Input : 55 Output : 55 in Binary : 0b110111 55 in Octal : 0o67 55 in Hexadecimal : 0x37 Input : 282 Output : 282 in Binary : 0b100011010 282 in Octal : 0o432 282 in Hexadecimal : 0x11a
One solution is to use the approach discussed in below post.
Python provides direct functions for standard base conversions like bin(), hex() and oct()
32 in Binary : 0b100000 32 in Octal : 0o40 32 in Hexadecimal : 0x20
This article is contributed by Pramod Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Sum of digits written in different bases from 2 to n-1
- Sum of the digits of a number N written in all bases from 2 to N/2
- Python program to convert float decimal to Octal number
- Python program to convert decimal to binary number
- Python program to convert hex string to decimal
- Python program to convert any base to decimal by using int() method
- Convert Decimal to String in Python
- Convert from any base to decimal and vice versa
- Convert all substrings of length 'k' from base 'b' to decimal
- Convert a given Decimal number to its BCD representation
- Program to convert Hexa-Decimal Number to its equivalent BCD
- Program to Convert BCD number into Decimal number
- Program to convert a BCD to Hexa-Decimal Number
- Decimal Functions in Python | Set 1
- Decimal Functions in Python | Set 2 (logical_and(), normalize(), quantize(), rotate() ... )
- Binary to decimal and vice-versa in python
- Python | Decimal compare() method
- Python | Decimal to binary list conversion
- Python | Decimal is_subnormal() method
- Python | Decimal logb() method