hbutils.binary.uint

CUnsignedIntType

class hbutils.binary.uint.CUnsignedIntType(size: int)[source]
Overview:

Unsigned int type.

__init__(size: int)[source]

Constructor of CUnsignedIntType.

Parameters:

size – Size of the type.

read(file: BinaryIO) → int[source]

Read unsigned int value.

Parameters:

file – Binary file, io.BytesIO is supported as well.

Returns:

Unsigned int value.

property size

Size of the given type.

write(file: BinaryIO, val: int)[source]

Write unsigned int value to binary IO object.

Parameters:
  • file – Binary file, io.BytesIO is supported as well.

  • val – Unsigned int value to write.

c_byte

hbutils.binary.uint.c_byte = <hbutils.binary.uint.CUnsignedIntType object>

Alias for c_uint8.

c_ushort

hbutils.binary.uint.c_ushort = <hbutils.binary.uint.CUnsignedIntType object>

Alias for c_uint16.

c_uint

hbutils.binary.uint.c_uint = <hbutils.binary.uint.CUnsignedIntType object>

Alias for c_uint32 (in 64-bits OS).

Note

Size of c_uint is the same as that in C language, which mainly depends on CPU and OS.

c_ulong

hbutils.binary.uint.c_ulong = <hbutils.binary.uint.CUnsignedIntType object>

Alias for c_uint64 (in 64-bits OS).

Note

Size of c_ulong is the same as that in C language, which mainly depends on CPU and OS.

c_ulonglong

hbutils.binary.uint.c_ulonglong = <hbutils.binary.uint.CUnsignedIntType object>

Alias for c_uint64 (in 64-bits OS).

Note

Size of c_ulonglong is the same as that in C language, which mainly depends on CPU and OS.

c_uint8

hbutils.binary.uint.c_uint8 = <hbutils.binary.uint.CUnsignedIntType object>
Overview:

Reading and writing unsigned integer with 8-bits.

Examples::
>>> import io
>>> from hbutils.binary import c_uint8
>>> 
>>> with io.BytesIO(b'Þ­¾ï') as file:
...     print(c_uint8.read(file))
...     print(c_uint8.read(file))
...     print(c_uint8.read(file))
...     print(c_uint8.read(file))
222
173
190
239
>>> with io.BytesIO() as file:
...     c_uint8.write(file, 222)
...     c_uint8.write(file, 173)
...     c_uint8.write(file, 190)
...     c_uint8.write(file, 239)
...     print(file.getvalue())
b'Þ­¾ï'

c_uint16

hbutils.binary.uint.c_uint16 = <hbutils.binary.uint.CUnsignedIntType object>
Overview:

Reading and writing unsigned integer with 16-bits.

Examples::
>>> import io
>>> from hbutils.binary import c_uint16
>>> 
>>> with io.BytesIO(b'Þ­¾ï4Vx') as file:
...     print(c_uint16.read(file))
...     print(c_uint16.read(file))
...     print(c_uint16.read(file))
...     print(c_uint16.read(file))
44510
61374
13330
30806
>>> with io.BytesIO() as file:
...     c_uint16.write(file, 44510)
...     c_uint16.write(file, 61374)
...     c_uint16.write(file, 13330)
...     c_uint16.write(file, 30806)
...     print(file.getvalue())
b'Þ­¾ï4Vx'

c_uint32

hbutils.binary.uint.c_uint32 = <hbutils.binary.uint.CUnsignedIntType object>
Overview:

Reading and writing unsigned integer with 32-bits.

Examples::
>>> import io
>>> from hbutils.binary import c_uint32
>>> 
>>> with io.BytesIO(b'Þ­¾ï4Vx') as file:
...     print(c_uint32.read(file))
...     print(c_uint32.read(file))
4022250974
2018915346
>>> with io.BytesIO() as file:
...     c_uint32.write(file, 4022250974)
...     c_uint32.write(file, 2018915346)
...     print(file.getvalue())
b'Þ­¾ï4Vx'

c_uint64

hbutils.binary.uint.c_uint64 = <hbutils.binary.uint.CUnsignedIntType object>
Overview:

Reading and writing unsigned integer with 64-bits.

Examples::
>>> import io
>>> from hbutils.binary import c_uint64
>>> 
>>> with io.BytesIO(b'Þ­¾ï4Vx') as file:
...     print(c_uint64.read(file))
8671175388484775390
>>> with io.BytesIO() as file:
...     c_uint64.write(file, 0x78563412efbeadde)
...     print(file.getvalue())
b'Þ­¾ï4Vx'