Unsigned but negative?
PsyenceFact
Posts: 29
If anyone can explain the following behaviour I'd be very grateful.
Plain old integers produce the expected result - the type cast results in the decimal value of the two's complement representation of the negative number.
Just wondering if anyone has experienced anything similar, or can explain what's going on.
Andy
stack_var long var_long stack_var slong var_slong var_slong = -1000 var_long = type_cast(var_slong) send_string 0, "'var_slong = ', itoa(var_slong)" send_string 0, "'var_long = ', itoa(var_long)"The code produces this output:
Line 6 (18:34:25):: var_slong = -1000 Line 7 (18:34:25):: var_long = -1000Now forgive me for being picky but isn't one of the points of an unsigned data type that it is, in fact, unsigned? Testing (var_long < 0) gives the expected result of zero, but even so...
Plain old integers produce the expected result - the type cast results in the decimal value of the two's complement representation of the negative number.
Just wondering if anyone has experienced anything similar, or can explain what's going on.
Andy
0
Comments
Paul
Andy
Andy
Paul