#Getting a negative number from two u64 addresses

1 messages · Page 1 of 1 (latest)

gray zenith
#

I am trying to calculate the jmp offset of an instruction which has to be a negative number because I am jumping backwards. My addresses are u64 and I am trying to calculate the offset with the 2 u64 addresses and casting the result as a negative number but everytime I try I get a panic error in regards to truncating the value and if I print out the value as two u64 I get a lot of F's. How do I get the integers to wrap around?

Thanks,

Connor

craggy spruce
#

you probably just want to use @bitCast instead of @intCast:
@intCast panics if the numeric value does not fit into the destination type; in your case it's probably because you have a very big u64 (≥ 2^63) - @bitCast just casts the bits, so you'll get the 2's complement behaviour you want