I've been investigating how i8 and u8 work. Along with how casting and stuff is done. I've found something weird and I think I'm missing some knowledge on either how the compiler is doing something or how the hardware is doing something.
fn main() {
let n: u8 = 255; //x &n 0x7fffffffe12f: 0x00_00_00_ff
let m: i8 = n as i8; //x &m 0x7fffffffe12e: 0x00_00_ff_ff
let p: i8 = -1; //x &p 0x7fffffffe12d: 0x00_ff_ff_ff
let o: i8 = m - p ; //x &o 0x7fffffffe12c: 0xff_ff_ff_00
println!("hello {} {}", n, m);
}
So when I look at the memory it looks like the previous values are pushed to the left. I don't know much assembly but I don't see that bit shifting happening anywhere. So my question is what is causing those bits to appear to be shifting? What is actually happening? Who does the sizing? Does the compiler keep track of the sizing and use the assembly suffixs to perform operations on the byte or does the hardware somehow know the sizes it needs to deal with?
Thanks for the help
Edit:
Should've mentioned I also tried the same thing in C and got the basically the same results. So this isn't really a rust specific question. Rust just drove me to ask the question.