Fawaz,
>We have to test whether this will work with negative numbers.
You need to find out how informix expects you to represent a negative
number. Most likely 2s complement.
For two's complement negatives, you need to invert the bit pattern and add
1. I think this will work ...
MAKE8BYTE:
* Initialise output as 0
OUTINT = STR(CHAR(0), 8)
CARRY = @TRUE
IF ININT LT 0 THEN
NEGATIVE = @TRUE
ININT = ABS(ININT)
END ELSE
NEGATIVE = @FALSE
END
FOR I = 1 TO 7
* Get lowest 8bits
LOWESTBYTE = BITAND(ININT, 255)
IF NEGATIVE THEN
IF CARRY THEN
IF LOWESTBYTE LT 255 THEN
CARRY = @FALSE
LOWESTBYTE = BITAND(BITNOT(LOWESTBYTE), 255) + 1
END
END ELSE
LOWESTBYTE = BITAND(BITNOT(LOWESTBYTE), 255)
END
END
* Convert this to a byte representation and place it in the output
integer
OUTINT[8-I, 1] = CHAR(LOWESTBYTE)
* Remove the lowest byte 8bits from the
integer
ININT = INT(ININT/256)
NEXT I
* Top bit is sign bit, so only work on lowest 7 bits, but when doing
inversion, still invert top bit
LOWEST7 = BITAND(ININT, 127)
IF NEGATIVE THEN
IF CARRY THEN
IF LOWEST7 LT 127 THEN
CARRY = @FALSE
LOWEST7 = BITAND(BITNOT(LOWEST7), 255) + 1
END
END ELSE
LOWEST7 = BITAND(BITNOT(LOWEST7), 255)
END
END
OUTINT[1, 1] = CHAR(LOWEST7)
RETURN
--
u2-users mailing list
[EMAIL PROTECTED]
http://www.oliver.com/mailman/listinfo/u2-users