Unsigned but negative?
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
Comments
Paul
define_function char[4] IntToChar(slong num) { stack_var long cast_num stack_var char obj[4] cast_num = type_cast(num) for (n = 4; n; n--) { obj[n] = type_cast(cast_num >> ((4 - n) * 8)) } return obj }I'll just sweep the minus sign under the NetLinx carpet and move on.Andy
Andy
Paul