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.

Filename, size & hash SHA256 hash help File type Python version Upload date
cinc-1.0.1.tar.gz (8.2 kB) Copy SHA256 hash SHA256 Source None Apr 9, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page