I'm trying to decode the result of the Python os.wait() function. This returns, according to the Python docs:
a tuple containing its pid and exit status indication: a 16-bit number, ... |
How can I convert a string of bytes into an int in python?
Say like this: 'y\xcc\xa6\xbb'
I came up with a clever/stupid way of doing it:
sum(ord(c) << (i * 8) for ...
|
The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency ... |
What is the correct way to get the length of a string in Python, and then convert that int to a byte array? What is the right way to print that ... |
I have a python program I've inherited and am trying to extend.
I have extracted a two byte long string into a string called pS.
pS 1st byte is 0x01, the second is ... |
I have a non-negative int and I would like to efficiently convert it to a big-endian string containing the same data. For example, the int 1245427 (which is 0x1300F3) should ... |
I have a list of bytes as follows
pkt_bytes = [ 0x02,0x07, 0xff,0xff ,0x00,0x03]
in the position 0xff,0xff I want to put a 16bit short integer
How do I do it
Regards
|
|
assume i have to store few integer numbers like 1024 or 512 or 10240 or 900000 in a file, but the condition is that i can consume only 4 bytes (not ... |
I want to get a list of ints representing the bytes in a string.
|
I have a list of integer ascii values that I need to transform into a string (binary) to use as the key for a crypto operation. (I am re-implementing java crypto ... |
I'm converting the following string to it's unsigned integer representation:
str = '\x00\x00\x00\x00\x00\x00\x01\xFF'
I can use struct.unpack('8B', str) to get the tuple representation (0,0,0,0,0,0,1,255), but what's the quickest/easiest way to convert this tuple ... |
I have 2 32bit unsigned integers..
777007543
and
114997259
and the string of bytes..
0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58
How do I get python to give me the concatenation of these 3 such that ... |
I want to convert an 32-byte (although I might need other lengths) integer to a bytes object in python. Is there a clean and simple way to do this?
|
This seems like it should be simple, but I haven't been able to figure it out...
I'm trying to use PySerial to communicate with a microcontroller. I want to ... |
I need to send message of bytes in Python and I need to convert unsigned integer number to byte array. How to convert integer value to array of four bytes in ... |
Re: Store as 1 byte integer? Posted 13 April 2011 - 05:37 AM When I first read this I thought, but python doesn't have arrays! Of course, it does have a butt load of packages, so I'm guessing this one. I was curious how a string might do. This was my first test: >>> a = [ random.randint(65,100) for i in ... |
#include int main(void) { unsigned int i = 16777215; unsigned char * ptr; /* Print each byte in i */ for (ptr = (char *) &i + sizeof(i) ... |
def waveto32(data): num = 2048 xdata = array.array('B') for i in range(0,num,3): xdata.append(data[i]) xdata.append(data[i+1]) xdata.append(data[i+2]) ... |
|
i'm writing and pure python ldap client mainly because i'm working with sun one not open ldap. this requires BER encoding of the requests. if an items length is longer than 255 i have to split it over 2 bytes so how do i go from 43981 to a byte string '\xab\xcd' >>> chr(0xabcd) Traceback (most recent call last): File "", ... |
|
by faulkner Tue Jun 20, 2006 6:00 am this baby will convert any number [int, str, long] in any base in range(-256,257) to any other base in that range. Code: Select all def rebase(i, frombase=None, tobase=None, fromalphabet=None, toalphabet=None, resize=1, too_big=40000, debug=False): ''' if frombase is not specified, it is guessed from the type and/or char in ... |