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?
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.
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.
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.
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.
"04 f8 00 50".replace(' ', '').decode('hex')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With