Relative Content

Tag Archive for rustcasting

How can I cast between f32 and u32 without changing the bits

So i’m making a virtual machine which takes in a sequence of 32 bits (so multiple batches of 32 bits) and they’re represented as u32s, but in reality the number could be a f32 but just wrapped in a u32. My program knows when a u32 actually represents a f32, but I’m not sure how to convert them. If I used as would it do rounding or would it just shove the bits between the formats (I want the latter)? Because what I want is to convert between u32 and f32 without changing any of the underlying bits, I just want to call it a different thing. Here for example I’m worried that my as u32 won’t be doing what I want it to be doing: