; ***** Some number manipulation utilities ***** ;========================================== ; Sign extension: ; This macro extends the sign of a two's complement value of any bit width ; to a signed 32-bit integer. ; PARAMETERS: N is the value, BIT is the bit width of the value. ; Note that if the bit width is a constant then this macro ; will compile down to just a few Venom bytecodes. #Define SignExtend(val,bitwid) ((val << (32-bitwid)) Div (1 << (32-bitwid))) ;test the macro: To main Print SignExtend(7,4),CR Print SignExtend(15,4),CR End ;========================================== ; Convert raw bytes to a Float value: ; This procedure will convert the four bytes at the start of ; an array into a Float value and return the value. ; The array may be of any numeric type. To ArrayToFloat(byteArray) Local flt := 1.0 ; create a local variable of type Float. Local ptr := @flt As Int ; get address of the variable. ;Print ~????(ptr):-8,CR ????ptr := ????(byteArray.Address) ; Copy array data to variable Return flt End ;========================================== ; Convert two raw bytes to a signed integer value: ; This procedure will convert the two bytes at the start of ; an array into a signed integer value and return the value. ; The array may be of any numeric type. To TwoBytesInArrayToSignedInteger(ar) Return SignExtend(??(ar.Address), 16) End