How can I print 4 bytes as an integer

OSM10

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.

John La Rooy

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I print 4 bytes as an integer

From Dev

How can I print an integer number displaying 4 decimal digits?

From Dev

Python: How can I print bytes?

From Java

How can I print error and other counts in Scrapy as integer variable?

From Dev

Can I specify an integer constant by its bytes?

From Dev

How can I split binary into 4 bytes sections?

From Dev

How to reverse the 4 bytes of an unsigned integer?

From Dev

How do I read out the first 4 bytes in javascript, turn it into an integer and remove the rest?

From Dev

How can I print how many bytes has been read to console with Assembly?

From Dev

How can I convert a buffer of a slice of bytes (&[u8]) to an integer?

From Dev

How can I convert a pair of bytes into a signed 16-bit integer using Lua?

From Dev

how do I print the contents of an array of bytes as bytes?

From Dev

Hex to integer (4 bytes)

From Dev

Combining 4 Bytes To Integer

From Dev

Hex to integer (4 bytes)

From Dev

Combining 4 Bytes To Integer

From Dev

How can I print this?

From Dev

Why IPv4 address is in bytes and can not be in integer range?

From Dev

How can I print json array in Angular 4?

From Dev

how do I print an integer in Swift

From Dev

What does an integer that has zero in front of it mean and how can I print it?

From Dev

how to print 2 or 4 bytes in hex format in C

From Dev

how to print 2 or 4 bytes in hex format in C

From Dev

NASM assembly, How to print the first 4 bytes of a string array

From Dev

How can I properly read the sequence of bytes from a hyper::client::Request and print it to the console as a UTF-8 string?

From Dev

How can I print a Maybe?

From Dev

How can I print 413284921265094656?

From Dev

How can I print 413284921265094656?

From Dev

I can't seem to print out a string from a structure but I can print an integer

Related Related

  1. 1

    How can I print 4 bytes as an integer

  2. 2

    How can I print an integer number displaying 4 decimal digits?

  3. 3

    Python: How can I print bytes?

  4. 4

    How can I print error and other counts in Scrapy as integer variable?

  5. 5

    Can I specify an integer constant by its bytes?

  6. 6

    How can I split binary into 4 bytes sections?

  7. 7

    How to reverse the 4 bytes of an unsigned integer?

  8. 8

    How do I read out the first 4 bytes in javascript, turn it into an integer and remove the rest?

  9. 9

    How can I print how many bytes has been read to console with Assembly?

  10. 10

    How can I convert a buffer of a slice of bytes (&[u8]) to an integer?

  11. 11

    How can I convert a pair of bytes into a signed 16-bit integer using Lua?

  12. 12

    how do I print the contents of an array of bytes as bytes?

  13. 13

    Hex to integer (4 bytes)

  14. 14

    Combining 4 Bytes To Integer

  15. 15

    Hex to integer (4 bytes)

  16. 16

    Combining 4 Bytes To Integer

  17. 17

    How can I print this?

  18. 18

    Why IPv4 address is in bytes and can not be in integer range?

  19. 19

    How can I print json array in Angular 4?

  20. 20

    how do I print an integer in Swift

  21. 21

    What does an integer that has zero in front of it mean and how can I print it?

  22. 22

    how to print 2 or 4 bytes in hex format in C

  23. 23

    how to print 2 or 4 bytes in hex format in C

  24. 24

    NASM assembly, How to print the first 4 bytes of a string array

  25. 25

    How can I properly read the sequence of bytes from a hyper::client::Request and print it to the console as a UTF-8 string?

  26. 26

    How can I print a Maybe?

  27. 27

    How can I print 413284921265094656?

  28. 28

    How can I print 413284921265094656?

  29. 29

    I can't seem to print out a string from a structure but I can print an integer

HotTag

Archive