DEV Community

Discussion on: Why I started learning Rust and impressions after a week

Collapse
 
pdmahon1 profile image
Peter Mahon • Edited

I’m not familiar with Rust, so I was intrigued by your article. As someone who learned C in school, I can see some parallels between the two languages, and I am interested to learn and try some of these features!

On a side note, you have a small error regarding the min/max of i8 values. “[An i8] variable can store -(2^n - 1) to (2^n - 1)-1.”

I see your intention, but be careful with the notation. The min is -(2^(n-1)) and the max is (2^(n-1))-1. Then your min and max values for i8 are -128 and +127.

If you’re unsure why that is, understand that in a signed byte, the left-most digit declares whether a number is positive (0) or negative (1). So 0111 1111 is 127, and when you add +1, it becomes 1000 000. That first digit says the value is negative, so it’s now -128 instead of +128. Increasing it by 1 makes 1000 0001, which is like saying -128 +1 = -127. Not sure if you knew this already, but certainly someone will stumble on this and learn something, known as “2’s Complement.”