I have an array
of 4 bytes
that I need to print it's value as an Integer
. This is very easy in C, as I can cast and print with something like this:
printf("Integer Value = %i", (int) pointer_to_4_bytes_array);
Thanks.
I have an array
of 4 bytes
that I need to print it's value as an Integer
. This is very easy in C, as I can cast and print with something like this:
printf("Integer Value = %i", (int) pointer_to_4_bytes_array);
Thanks.
In Python2 (works on 3 too), you can use the struct
module.
>>> import struct
>>> struct.unpack(">L","1234")[0]
825373492
In Python3.2+, int.from_bytes
does what you want. See @ryrich's answer
>>> int.from_bytes(b"1234",'big')
825373492