Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert HEX data into BINARY data?

Tags:

python

I am trying to send Binary data using python raw socket. For that i will do following.

s = '\x01\x00\x12\x59' # some binary data
sock.send(s)           # assuming "sock" is a valid, open socket object

i have created a DATAGRAM in HEX in by sniffing a network traffic with wireshark.Which i want to send over the network.This hand made datagram is like

"04 f8 00 50 4f 30 fb 47 28 62 a7 6d 50 02 02 00 d2 7f 00 00"

So i wanna convert this above mentioned HEX datagram into the binary format like "\x01\x00\x12\x59". How can i do that?

like image 952
Dev.K. Avatar asked Jul 13 '11 15:07

Dev.K.


People also ask

How do you convert hex to binary?

Hexadecimal to binarySplit the hex number into individual values. Convert each hex value into its decimal equivalent. Next, convert each decimal digit into binary, making sure to write four digits for each value. Combine all four digits to make one binary number.

How do you convert from hexadecimal to numeric?

The conversion of hexadecimal to decimal is done by using the base number 16. The hexadecimal digit is expanded to multiply each digit with the power of 16. The power starts at 0 from the right moving forward towards the right with the increase in power. For the conversion to complete, the multiplied numbers are added.

Is hex binary data?

The xs:hexBinary data type represents hex-encoded binary data. Derived from data type xdt:anyAtomicType. The lexical form of xs:hexBinary is a sequence of characters in which each binary octet is represented by two hexadecimal digits.

How does the hex value relate to the binary value?

Binary and Hexadecimal numbering systems are positional number systems which use different bases. Binary number systems use a base-2 while hexadecimal numbers use base-16.


1 Answers

"04 f8 00 50".replace(' ', '').decode('hex')
like image 66
Josh Lee Avatar answered Oct 28 '22 19:10

Josh Lee