Programming & Design
Question:
How to write a program to convert Hexadecimal to Binary in Python or Psuedocode?
Barry O
2008-12-02 11:42:50 UTC
Title says it all. Best answer to the best answer
Three answers:
lansingstudent09101
2008-12-02 11:59:11 UTC
Here's a function to turn a given hex number (1 digit) to bin:
if (number is F)
return 1111
if (number is E)
return 1110
if (number is D)
return 1101
if (number is C)
return 1100
if (number is B)
...[[~omitted for space, I think you can figure that out~]]
Now all the program has to do is
get inputNumber from user
convert leftmost hexnumber to bin.
print it
convert next left hexnumber to bin
print it
and so on....(sorry, don't know python)
edit: (assume MSB is on the left.)
wernecke
2016-12-30 15:02:49 UTC
Python Hexadecimal
anonymous
2008-12-03 00:23:24 UTC
Python apparently has a simple built-in way to do this.
import binascii
#.... get the Hexadecimal string you want to convert in a variable called hex_string
binary_string = binascii.unhexlify(hex_string)
# binary_string now stores the converted string.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...