Skip to main content

Fast fixed-sized C-like integer types.

Project description

cinc provides fixed-width C-like integer types. These types are designed to be as fast as Python’s built-in int type.

Usage

Signed types are named “intN” and unsigned types are named “uintN”, where “N” is the number of bits. Types for 8, 16, 32 and 64 bits are provided.

cinc integers can be constructed from Python ints or cast from another cinc type.

>>> x = uint32(0xFFFFFFFF)
>>> uint16(x)
cinc.uint16(65535)

Arithmetic

cinc integers support all arithmetic operators. All cinc integers are immutable, so operators return new objects.

There is no need to explicitly cast different types when using them together. Every cinc type is compatible with every other cinc type:

>>> x = uint32(2)
>>> y = int32(2)
>>> x + y
cinc.uint32(4)
>>> y + x
cinc.int32(4)

The object returned by operators has the same type as the left operand.

cinc integers also have methods for bit rotate operations as well as bit extraction and insertion.

Most operators and methods expect cinc objects for their arguments, but some accept Python ints because it is common to use them with literals:

  • The << and >> operators.

  • The lrotate and rrotate methods.

  • The extract and insert methods.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cinc-1.0.1.tar.gz (8.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page