Understanding how `readi` / `readu`, `writei` and `writeu` work, as well as the "8", "16", "32", "64" values

Hello dear users,

I am currently working on buffers, but I’m having some trouble understanding how readi / readu, writei and writeu work, as well as the “8”, “16”, “32”, “64” values.

Looking forward to your response!

Best regards.

These functions are used to read and write integer values to and from buffers:

readi: Reads a signed integer from the buffer.
readu: Reads an unsigned integer from the buffer.
writei: Writes a signed integer to the buffer.
writeu: Writes an unsigned integer to the buffer.

These numbers refer to the bit size of the integers you’re working with:

8-bit: Can store values from -128 to 127 (signed) or 0 to 255 (unsigned).
16-bit: Can store values from -32,768 to 32,767 (signed) or 0 to 65,535 (unsigned).
32-bit: Can store values from -2,147,483,648 to 2,147,483,647 (signed) or 0 to 4,294,967,295 (unsigned).
64-bit: Can store values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (signed) or 0 to 18,446,744,073,709,551,615 (unsigned).
If you wish to read more: Byte buffer type | Luau RFCs (luau-lang.org)

3 Likes