BCS Primitives

Here is a list of primitives, and more descriptions below. Keep in mind all numbers are stored in little-endian byte order.

TypeNumber of bytesDescription
bool1Boolean value (true or false)
u81Unsigned 8-bit integer
u162Unsigned 16-bit integer
u324Unsigned 32-bit integer
u648Unsigned 64-bit integer
u12816Unsigned 128-bit integer
u25632Unsigned 256-bit integer
address32Aptos Address (32-byte integer)
uleb1281-32Unsigned little-endian base-128 integer

Bool

A boolean is a single byte. 0x00 represents false, 0x01 represents true. All other values are defined as invalid.

Examples:

ValueBCS Serialized Value
false0x00
true0x01

U8

A U8 is an unsigned 8-bit integer (1 byte).

Examples:

ValueBCS Serialized Value
00x00
10x01
160x0F
2550xFF

U16

A U16 is an unsigned 16-bit integer (2 bytes).

Examples:

ValueBCS Serialized Value
00x0000
10x0001
160x000F
2550x00FF
2560x0100
655350xFFFF

U32

A U32 is an unsigned 32-bit integer (4 bytes).

Examples:

ValueBCS Serialized Value
00x00000000
10x00000001
160x0000000F
2550x000000FF
655350x0000FFFF
42949672950xFFFFFFFF

U64

A U64 is an unsigned 64-bit integer (8 bytes).

Examples:

ValueBCS Serialized Value
00x0000000000000000
10x0000000000000001
160x000000000000000F
2550x00000000000000FF
655350x000000000000FFFF
42949672950x00000000FFFFFFFF
184467440737095516150xFFFFFFFFFFFFFFFF

U128

A U128 is an unsigned 128-bit integer (16 bytes).

Examples:

ValueBCS Serialized Value
00x00000000000000000000000000000000
10x00000000000000000000000000000001
160x0000000000000000000000000000000F
2550x000000000000000000000000000000FF
655350x0000000000000000000000000000FFFF
42949672950x000000000000000000000000FFFFFFFF
184467440737095516150x0000000000000000FFFFFFFFFFFFFFFF
3402823669209384634633746074317682114550xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

U256

A U256 is an unsigned 256-bit integer (32 bytes).

Examples:

ValueBCS Serialized Value
00x0000000000000000000000000000000000000000000000000000000000000000
10x0000000000000000000000000000000000000000000000000000000000000001
160x000000000000000000000000000000000000000000000000000000000000000F
2550x00000000000000000000000000000000000000000000000000000000000000FF
655350x000000000000000000000000000000000000000000000000000000000000FFFF
42949672950x00000000000000000000000000000000000000000000000000000000FFFFFFFF
184467440737095516150x000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF
3402823669209384634633746074317682114550x00000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1157920892373161954235709850086879078532699846656405640394575840079131296399350xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Address

An address is the 32-byte representation of a storage slot on Aptos. It can be used for accounts, objects, and other addressable storage.

Addresses, have special addresses 0x0 -> 0xA, and then full length addresses. Note, for legacy purposes, addresses missing 0's in front, are extended by filling the missing bytes with 0s.

Examples:

ValueBCS Serialized Value
0x00x0000000000000000000000000000000000000000000000000000000000000000
0x10x0000000000000000000000000000000000000000000000000000000000000001
0xA0x000000000000000000000000000000000000000000000000000000000000000A
0xABCDEF (Legacy shortened address)0x0000000000000000000000000000000000000000000000000000000000ABCDEF
0x0000000000000000000000000000000000000000000000000000000000ABCDEF0x0000000000000000000000000000000000000000000000000000000000ABCDEF
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Uleb128

A uleb128 is a variable-length integer used mainly for representing sequence lengths. It is very efficient at storing small numbers, and takes up more space as the number grows. Note that the Aptos specific implementation only supports representing a u32 in the uleb128. Any value more than the max u32 is considered invalid.

Examples:

ValueBCS Serialized Value
00x00
10x01
1270x7F
1280x8001
2400xF001
2550xFF01
655350xFFFF03
167772150xFFFFFF07
42949672950xFFFFFFFF0F