Numerical bytes

Hello! I was just wondering if anybody knew the space (bytes) numbers (integers, unsigned integers, floats, everything) take in Rust?

sorry if this is a stupid question, I am new to Rust and low-level programming in general :sweat_smile:

Certainly the compiler does know.

Thank you!

Also, if unsigned integers take up the same amount of memory as signed integers, why do unsigned integers exist in the first place? Wouldn't everyone only use signed integers?

Signed integers use up half of their range on negative numbers, which are unnecessary for many use cases. (For example, a vector's length can't be negative.)

This means that u8 can count up to 255, while i8 can only go up to 127.

And for use cases where negative numbers don't make sense, it's actually useful to know that you will never get a negative number.

1 Like


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.