Sized Integers

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
srogers
Posts: 11
Joined: Sun Feb 06, 2022 12:25 am

Sized Integers

Post by srogers » Fri Mar 04, 2022 6:51 pm

I am trying to discover how to declare an integer in MicroPython as a particular size (or signed type).

I'd like the capability to do these types (expressed in 'C' or "C++' notation:

Code: Select all

int_8
uint_8
int_16
uint_16
int_32
uint_32
How is this done in MicroPython 1.18?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Sized Integers

Post by dhylands » Fri Mar 04, 2022 7:22 pm

Micropython has 2 representations of an integer. One is SMALLINT which doesn't require heap allocation and is a 31-bit signed number. The second is an infinite precision integer which can have as many digits as it needs.

For creating sized data structures, for storing to disk, sending over the serial/network, etc, you can use the uctypes or struct

Post Reply