Best way to represent an 8 bit integer?

As the title says, I want to know the best way to represent an 8 bit integer. I thought of using Vector2int16 but that would result in 24 bits being unused. I could use a string but they use pointers and I don’t know how much that would effect the space it occupies.

I think you are thinking at too low of a level.

Lua is a high-level language, meaning things like literal type memory size shouldn’t be of your concern about 99% of the time. Lua was built as an application extension scripting language; it is designed to allow for rapid code creation. The cost of this higher abstraction is being unable to fine-tune performance and memory utilization as you describe here.

If you really need an 8 bit number, I’m assuming you are using a lot of numbers to, say, represent a large set of values. The best you can do is use the bit32 library to represent your data structure as a table of numbers (synonymous with 4-byte words) and then read/write using bit32 from specific offsets.

2 Likes

There’s also the bitbuffer module for encoding any number of bits in base64, which might be better for data storage.

1 Like