I need to calculate an error correction code for an old protocol.
I calculate the integer 4617 and want to code the 2s compliment in ASCII
hex EDF7. When issue the following.
hex(-4617)
'-0x1209'
Does anyone know a clean way to get to the desired results? My ECC will always
be 16 bit (4
On 2014-08-01 21:35, bSneddon wrote:
I need to calculate an error correction code for an old protocol.
I calculate the integer 4617 and want to code the 2s compliment in ASCII
hex EDF7. When issue the following.
hex(-4617)
'-0x1209'
Does anyone know a clean way to get to the desired
On Friday, August 1, 2014 4:47:20 PM UTC-4, MRAB wrote:
On 2014-08-01 21:35, bSneddon wrote:
I need to calculate an error correction code for an old protocol.
I calculate the integer 4617 and want to code the 2s compliment in ASCII
hex EDF7. When issue the following.
I have an integer that I want to encode as a hex string, but I don't
want 0x at the beginning, nor do I want L at the end if it happened
to be a long. The result needs to be something I can pass to int(h, 16)
to get back my original integer.
The brute force way works:
h = hex(i)
assert
On 12/24/12 09:36, Roy Smith wrote:
I have an integer that I want to encode as a hex string, but I don't
want 0x at the beginning, nor do I want L at the end if it happened
to be a long. The result needs to be something I can pass to int(h, 16)
to get back my original integer.
The brute
In article mailman.1256.1356364625.29569.python-l...@python.org,
Tim Chase python.l...@tim.thechases.com wrote:
On 12/24/12 09:36, Roy Smith wrote:
I have an integer that I want to encode as a hex string, but I don't
want 0x at the beginning, nor do I want L at the end if it happened
On 2012-12-24 15:58, Tim Chase wrote:
On 12/24/12 09:36, Roy Smith wrote:
I have an integer that I want to encode as a hex string, but I don't
want 0x at the beginning, nor do I want L at the end if it happened
to be a long. The result needs to be something I can pass to int(h, 16)
to get back
How can I concatenate 2 hex strings (e.g. '\x16' and '\xb9') then convert
the answer to an integer?
When I try i always end up with the ASCII equivalent!
Thanks,
Anthony
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, May 10, 2010 at 12:55 PM, Anthony Cole anthony.c...@gmail.com wrote:
How can I concatenate 2 hex strings (e.g. '\x16' and '\xb9') then convert
the answer to an integer?
When I try i always end up with the ASCII equivalent!
I think you want the `struct` module:
struct — Interpret
Anthony Cole wrote:
How can I concatenate 2 hex strings (e.g. '\x16' and '\xb9') then convert
the answer to an integer?
When I try i always end up with the ASCII equivalent!
Those are just bytestrings (assuming you're using Python 2.x), ie
strings using 1 byte per character. You can convert
Hello,
What will be a concise efficient way to convert a list/array.array of
n elements into a hex string? For e.g. given the bytes
[116, 111, 110, 103, 107, 97]
I would like the formatted string
0x74 0x6f 0x6e 0x67 0x6b 0x61
Is there an approach better than below:
hex = ''
for b in bytes
On Aug 2, 9:53 pm, Kurien Mathew [EMAIL PROTECTED] wrote:
Hello,
What will be a concise efficient way to convert a list/array.array of
n elements into a hex string? For e.g. given the bytes
[116, 111, 110, 103, 107, 97]
I would like the formatted string
0x74 0x6f 0x6e 0x67 0x6b 0x61
Kurien Mathew írta:
Hello,
What will be a concise efficient way to convert a list/array.array of
n elements into a hex string? For e.g. given the bytes
[116, 111, 110, 103, 107, 97]
I would like the formatted string
0x74 0x6f 0x6e 0x67 0x6b 0x61
Is there an approach better than below
On 2008-08-02, Zoltán Nagy [EMAIL PROTECTED] wrote:
Kurien Mathew írta:
Hello,
What will be a concise efficient way to convert a list/array.array of
n elements into a hex string? For e.g. given the bytes
[116, 111, 110, 103, 107, 97]
I would like the formatted string
0x74 0x6f 0x6e 0x67
On Aug 2, 9:29 am, Grant Edwards [EMAIL PROTECTED] wrote:
On 2008-08-02, Zoltán Nagy [EMAIL PROTECTED] wrote:
Kurien Mathew írta:
Hello,
What will be a concise efficient way to convert a list/array.array of
n elements into a hex string? For e.g. given the bytes
[116, 111, 110
On Jan 31, 7:09 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
Antonio Chay [EMAIL PROTECTED] writes:
AAA should be 414141
'AAA'.encode('hex')
8-O
Cool stuff!
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
Hello!
I need to transform a string from a file into a hexadecimal
representation, for example:
AAA should be 414141
With perl I do this with:
unpack(H*,AAA)
And with python I got this:
.join([str(hex(ord(x)))[2:] for x in AAA])
But seems a little weird for me.
Is there another way?
Thanks
Antonio Chay [EMAIL PROTECTED] writes:
AAA should be 414141
'AAA'.encode('hex')
--
http://mail.python.org/mailman/listinfo/python-list
You could also do:
.join(['%02x' % ord(c) for c in 'AAA'])
On 31 Jan 2008, at 14:09, Paul Rubin wrote:
Antonio Chay [EMAIL PROTECTED] writes:
AAA should be 414141
'AAA'.encode('hex')
--
http://mail.python.org/mailman/listinfo/python-list
On 31 Jan 2008, at 14:05, Antonio Chay wrote:
to a hex string. ADsSID com object will do this for me
however it
is a little slow. Can anybody point me in the right direction to
converting
a PySID to a hexstring.
Thx
import win32netcon
import win32net
import win32security
def report():
resume = 0
while 1:
filter
I am trying to create a hexstring of a NT4 user account sid which I can in
turn use to query an exchange 55 database. I believe I need to convert a
binary sid to a hex string. ADsSID com object will do this for me however it
is a little slow. Can anybody point me in the right direction
an exchange 55 database. I believe I need to convert a
binary sid to a hex string. ADsSID com object will do this for me however it
is a little slow. Can anybody point me in the right direction to converting
a PySID to a hexstring.
Thx
import win32netcon
import win32net
import win32security
def
Fredrik Lundh wrote:
[EMAIL PROTECTED] wrote:
Fredrik Lundh's solution works if the hex string starts with 0x
that's what interpret [it] as a Python literal meant.
I know from personal experience that the implications of that
sometimes go right over the head of a newbie. Did I do something
This is probably another newbie question...but...
even after reading quite some messages like '..hex to decimal',
'creating a hex value' , I can't figure this out:
If i do
m=66
n=hex(m)
n
'0x42'
i cannot use n as value for a variable that takes hex values, because it
throws:
error:
If you just want to convert a string to an integer, it would be:
int(n)
in your case it would be:
m=66
n=int(hex(m))
--
http://mail.python.org/mailman/listinfo/python-list
tim [EMAIL PROTECTED] wrote:
This is probably another newbie question...but...
even after reading quite some messages like '..hex to decimal',
'creating a hex value' , I can't figure this out:
If i do
m=66
n=hex(m)
n
'0x42'
i cannot use n as value for a variable that takes hex values,
but then i get :
m
66
n=int(hex(m))
Traceback (most recent call last):
File interactive input, line 1, in ?
ValueError: invalid literal for int(): 0x42
what am I missing here ?
thank you
Tim
avnit wrote:
If you just want to convert a string to an integer, it would be:
int(n)
avnit wrote:
If you just want to convert a string to an integer, it would be:
int(n)
That's what the OP tried and it didn't work.
BECAUSE you have to tell the int function what base the string is in
(even though it has 0x at the start).
int(n,16)
66
in your case it would be:
m=66
ok, but if i do
n=66
m=hex(n)
m
'0x42'
h=int(m,16)
h
66
I end up with 66 again, back where I started, a decimal, right?
I want to end up with 0x42 as being a hex value, not a string, so i can
pas it as an argument to a function that needs a hex value.
(i am trying to replace the
are converting from.
int(hex(m),16)
66
Fredrik Lundh's solution works if the hex string starts with 0x
(which it will when the string is created with the hex function).
int(hex(m),0)
66
But it won't work without the 0x.
int('0x1A',0)
26
int('0x1A',16)
26
int('1A',16)
26
int('1A',0)
Traceback
state what base you are converting from.
int(hex(m),16)
66
Fredrik Lundh's solution works if the hex string starts with 0x
(which it will when the string is created with the hex function).
aren't you converting from a hex string to a decimal value here?
--
http
tim wrote:
ok, but if i do
n=66
m=hex(n)
m
'0x42'
h=int(m,16)
h
66
I end up with 66 again, back where I started, a decimal, right?
I want to end up with 0x42 as being a hex value, not a string, so i can
pas it as an argument to a function that needs a hex value.
(i am
tim wrote:
I end up with 66 again, back where I started, a decimal, right?
I want to end up with 0x42 as being a hex value, not a string, so i can
pas it as an argument to a function that needs a hex value.
(i am trying to replace the 0x42 in the line midi.note_off(channel=0,
note=0x42)
Brett g Porter wrote:
tim wrote:
I end up with 66 again, back where I started, a decimal, right?
I want to end up with 0x42 as being a hex value, not a string, so i
can pas it as an argument to a function that needs a hex value.
(i am trying to replace the 0x42 in the line
On 2005-11-23, tim [EMAIL PROTECTED] wrote:
int(hex(m),16)
66
Fredrik Lundh's solution works if the hex string starts with 0x
(which it will when the string is created with the hex function).
aren't you converting from a hex string to a decimal value here?
No.
He's converting from
[EMAIL PROTECTED] wrote:
Fredrik Lundh's solution works if the hex string starts with 0x
that's what interpret [it] as a Python literal meant.
(which it will when the string is created with the hex function).
int(hex(m),0)
66
But it won't work without the 0x.
int('0x1A',0)
26
int
Tertius Cronje [EMAIL PROTECTED] wrote:
How do I get a hexvalued string to a format recognized for binary
calculation?
You're going to be embarrassed.
import binascii
s1 = '1C46BE3D9F6AA820'
s2 = '8667B5236D89CD46'
i1 = binascii.unhexlify(s1)
i2 = binascii.unhexlify(s2)
x = i1 ^i2
Hi,
How do I get a hexvalued string to a format recognized for binary
calculation?
import binascii
s1 = '1C46BE3D9F6AA820'
s2 = '8667B5236D89CD46'
i1 = binascii.unhexlify(s1)
i2 = binascii.unhexlify(s2)
x = i1 ^i2
TypeError: unsupported operand type(s) for ^: 'str' and 'str'
Many
Tertius Cronje wrote:
How do I get a hexvalued string to a format recognized for binary
calculation?
import binascii
s1 = '1C46BE3D9F6AA820'
s2 = '8667B5236D89CD46'
i1 = binascii.unhexlify(s1)
i2 = binascii.unhexlify(s2)
Try this instead:
i1 = long(s1, 16)
i2 = long(s2, 16)
x = i1 ^i2
--
Max M [EMAIL PROTECTED] wrote in news:41bf121e$0$280
[EMAIL PROTECTED]:
##
st = '80 00 00 00'
import binascii
import struct
s = ''.join([binascii.a2b_hex(s) for s in st.split()])
v = struct.unpack(f, s)[0]
print v
##
This one worked great for what I was trying to do.
Thanks to
On Tue, 14 Dec 2004 16:57:02 +0100, rumours say that Fredrik Lundh
[EMAIL PROTECTED] might have written:
how about:
# convert to byte string
import struct
s = .join([chr(int(c, 16)) for c in x])
v = struct.unpack(!f, s)
I think that the third line in the snippet above could also
Christos TZOTZIOY Georgiou wrote:
s = .join(x).decode(hex)
I am not sure I remember in which version of Python the hex codec was
added, but it is handy.
Of course, binascii could do this since 2.0 or so, but not
having to import another module *is* nice:
'ff12'.decode('hex')
'\xff\x12'
import
Max M wrote:
Oh, programmers loves this kind stuff. You should get tons of answers.
data = '80 00 00 00'
import Image
v = Image.fromstring(F, (1, 1), data, hex, F;32BF).getpixel((0, 0))
/F
--
http://mail.python.org/mailman/listinfo/python-list
Hi all,
Newbie Python programmer here, so please be patient. I have spent all
day googling for an answer to my problem, but everything I try fails to
work (or works from the Interpreter with a set value but not from my
code with dynamic values).
Okay, here is the general gist of the problem. I
[EMAIL PROTECTED] wrote:
Newbie Python programmer here, so please be patient. I have spent all
day googling for an answer to my problem, but everything I try fails to
work (or works from the Interpreter with a set value but not from my
code with dynamic values).
Okay, here is the general
45 matches
Mail list logo