473,748 Members | 10,539 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hexadecimal: how to convert 'ED6F3C01' to "\xED\x6F\x3C\x 01" inpython coding?

Hi,
how to change the hexadecimal 'ED6F3C01' (or 'ED 6F 3C 01') to
"\xED\x6F\x3C\x 01" in python coding?
When I take 'ED6F3C01' as a string and insert '\x' into it, I just got
the error information : invalid \x escape.
Thanks.

ouyang
Jun 27 '08 #1
6 4707
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ zxo102 <zx****@gmail.c om]
how to change the hexadecimal 'ED6F3C01' (or 'ED 6F 3C 01') to
"\xED\x6F\x3C\x 01" in python coding?
When I take 'ED6F3C01' as a string and insert '\x' into it, I just got
the error information : invalid \x escape.
[1]--'ED6F3C01'.deco de('hex')
Out[1]: '\xedo<\x01'

- --
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkg 4mtEACgkQn3IEGI Lecb7W6ACeNwr/vavkaXluvc0zeSa 4cy1N
YFIAoJjMsrRcLhq APRxKktUqt7miMT rs
=jxll
-----END PGP SIGNATURE-----
Jun 27 '08 #2
But this is not "\xED\x6F\x3C\x 01". I need it for
struct.unpack(' f',"\xED\x6F\x3 C\x01") to calculate the decimal value
(IEEE 754).
Any other suggestions?

ouyang

On 5月25日, 上午6时46分, Sebastian 'lunar' Wiesner <basti.wies...@ gmx.net>
wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ zxo102 <zxo...@gmail.c om]
how to change the hexadecimal 'ED6F3C01' (or 'ED 6F 3C 01') to
"\xED\x6F\x3C\x 01" in python coding?
When I take 'ED6F3C01' as a string and insert '\x' into it, I just got
the error information : invalid \x escape.

[1]--'ED6F3C01'.deco de('hex')
Out[1]: '\xedo<\x01'

- --
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkg 4mtEACgkQn3IEGI Lecb7W6ACeNwr/vavkaXluvc0zeSa 4cy1N
YFIAoJjMsrRcLhq APRxKktUqt7miMT rs
=jxll
-----END PGP SIGNATURE-----
Jun 27 '08 #3
On 5月25日, 上午6时59分, zxo102 <zxo...@gmail.c omwrote:
But this is not "\xED\x6F\x3C\x 01". I need it for
struct.unpack(' f',"\xED\x6F\x3 C\x01") to calculate the decimal value
(IEEE 754).
Any other suggestions?

ouyang

On 5月25日, 上午6时46分, Sebastian 'lunar' Wiesner<basti.w ies...@gmx.net>
wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[ zxo102 <zxo...@gmail.c om]
how to change the hexadecimal 'ED6F3C01' (or 'ED 6F 3C 01') to
"\xED\x6F\x3C\x 01" in python coding?
When I take 'ED6F3C01' as a string and insert '\x' into it, I just got
the error information : invalid \x escape.
[1]--'ED6F3C01'.deco de('hex')
Out[1]: '\xedo<\x01'
- --
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
iEYEARECAAYFAkg 4mtEACgkQn3IEGI Lecb7W6ACeNwr/vavkaXluvc0zeSa 4cy1N
YFIAoJjMsrRcLhq APRxKktUqt7miMT rs
=jxll
-----END PGP SIGNATURE------ 隐藏被引用文字 -

- 显示引用的文字 -
Hash: SHA1
I got it. Just simply use it like
struct.unpack(' f',"ED6F3C01".d ecode('hex')). It works now.

Thank you very much.
ouyang
Jun 27 '08 #4
On Sat, 2008-05-24 at 15:59 -0700, zxo102 wrote:
But this is not "\xED\x6F\x3C\x 01". I need it for
struct.unpack(' f',"\xED\x6F\x3 C\x01") to calculate the decimal value
(IEEE 754).
Any other suggestions?

ouyang
In fact it is exactly the same string. The repr of a string always
substitutes ascii values for their numeric equivalent, but those bytes
are still the underlying representation of the string.
>>[hex(ord(c)) for c in "\xefo<\x01 "]
['0xef', '0x6f', '0x3c', '0x1']

Cheers,
Cliff
On 5鏈25鏃, 涓婂崍6鏃46鍒 , Sebastian 'lunar' Wiesner <basti.wies...@ gmx.net>
wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ zxo102 <zxo...@gmail.c om]
how to change the hexadecimal 'ED6F3C01' (or 'ED 6F 3C 01') to
"\xED\x6F\x3C\x 01" in python coding?
When I take 'ED6F3C01' as a string and insert '\x' into it, I just got
the error information : invalid \x escape.
[1]--'ED6F3C01'.deco de('hex')
Out[1]: '\xedo<\x01'

- --
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkg 4mtEACgkQn3IEGI Lecb7W6ACeNwr/vavkaXluvc0zeSa 4cy1N
YFIAoJjMsrRcLhq APRxKktUqt7miMT rs
=jxll
-----END PGP SIGNATURE-----

--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #5
zxo102 wrote:
Hi,
how to change the hexadecimal 'ED6F3C01' (or 'ED 6F 3C 01') to
"\xED\x6F\x3C\x 01" in python coding?
If by "in python coding" you mean "in Python source code", then just
type it in with \x in front of each pair of hex digits, like you did above.

However if you mean e.g. how to change a data string x into a data
string y, something like this is what you want
>>import binascii
x = 'ED 6F 3C 01'
y = binascii.unhexl ify(x.replace(' ', ''))
y
'\xedo<\x01'

.... which is correct ('o' == '\x6f' and '<' == '\x3c'); see below:
>>' '.join(['%02x' % ord(c) for c in y])
'ed 6f 3c 01'
>>>len(y)
4

Does (len(y) == 4) surprise you?
When I take 'ED6F3C01' as a string and insert '\x' into it, I just got
the error information : invalid \x escape.
It's rather difficult to guess what you mean here ... insert how many
'\x'? where?? what gave you the error information??? Consider showing us
a copy/paste of exactly what you did and what was the response, like I
did above.
HTH,
John
Jun 27 '08 #6
Sebastian 'lunar' Wiesner wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[ zxo102 <zx****@gmail.c om]
> how to change the hexadecimal 'ED6F3C01' (or 'ED 6F 3C 01') to
"\xED\x6F\x3C\ x01" in python coding?
When I take 'ED6F3C01' as a string and insert '\x' into it, I just got
the error information : invalid \x escape.

[1]--'ED6F3C01'.deco de('hex')
Out[1]: '\xedo<\x01'
FWIW the 'hex' codec is just a big fat Python-coded wrapper around the
routines in the C-coded binascii module; here's the evidence:
>>'123'.decode( 'hex')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python25\li b\encodings\hex _codec.py", line 42, in hex_decode
output = binascii.a2b_he x(input)
TypeError: Odd-length string
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
90420
by: FalkoG | last post by:
Hello colleague I want to convert a floating number for example 5236.9856982 to a hexadecimal number. I'd tried several things but my problem is to convert the position after decimal point. I searched numberless websites but nothing could answer my question. I would be pleased to get some help. Regards
10
22795
by: pavithra.eswaran | last post by:
Hi, I would like to convert a single precision hexadecimal number to floating point. The following program seems to work fine.. But I do not want to use scanf. I already have a 32 bit hexadecimal number and would like to convert it into float. Can anyone tell me how to do it? int main() { float theFloat;
2
9755
by: akash deep batra | last post by:
hi i want to convert a 96 bit binary number into a hexadecimal number. e.g binary number= 001100010001010000100101011110111111010101110100010110000101011000101010000000000000000000000000 how can i do that in C#. also i want to convert a hexadecimal number (24 digits) into a binary number
1
3849
by: Charles | last post by:
Hi all, I need C# code for Implementing MD5 Algorithm.. Hope all would have heard of MD5 Algorith... Does any one have the C# coding for that Algorithm.. please Send... ITs URgent..... Thanks In Advance to all....................... With Regards,
15
35509
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
7
19225
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006 00000000000000001111111111111111 11111111111111111111111111111111 00000000000000000000000000000000 11111111111111110000000000000000
6
14638
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){ printf("%02x",bs); } }
5
1289
by: sweeet_addiction16 | last post by:
im coding in c....i need to accept an integer value(decimal) and then after converting it into hexadecimal value i need to write it into a file.i do not need to print it..so using fprintf along with %lx would not help me.for eg..if i have a decimal value of 60 to be passed to a function ..i need that function to convert it into hexadecimal value(eg 3c) and then write it into a file
11
7694
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've a question regarding Hexadecimal to binary conversion. Suppose I have a long hexadecimal string, and I would like to convert it to a binary string. How can I accomplish this with minimal code? I've seen other posts, but they are restricted to the size of the hexadecimal string, for they use Convert.ToString(...). EXA:
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project梡lanning, coding, testing, and deployment梬ithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.