Page 1 of 1

High and Low Order Words

Posted: Wed Nov 28, 2012 11:30 pm
by Biff
Hello

I need to pass an lParam value to the SendMessage API function that takes a high-word and low-word value. However, as Jade doesn't have a bitwise shift operator or an quivalent to the HIWORD/LOWORD macros (to my knowledge), I was hoping someone might be able to point me in the right the direction as to the best way to achieve this in Jade.

I could write an external function but I'd rather handle this from within Jade (6.3.10).

Thanks

Re: High and Low Order Words

Posted: Thu Nov 29, 2012 12:04 am
by ghosttie
You should be able to achieve a lot with bitOr and bitAnd.

I found some old shift methods on Integer, but I don't know if they're appropriate or even correct:

Code: Select all

shiftLeft(pI_Bits : Integer) : Integer; vars begin return self * (2 ^ pI_Bits); end;

Code: Select all

shiftRight(pI_Bits : Integer) : Integer; vars begin return self div (2 ^ pI_Bits); end;

Re: High and Low Order Words

Posted: Thu Nov 29, 2012 7:41 am
by murray
Bit shifting is unnecessary, as in this case you only need to select on word/byte boundaries.
You can typecast an Integer or Integer64 to a Binary and then pick the bytes that you require.
Remember to allow for the correct byte ordering (Intel architecture being little-endian).

quick example:

Code: Select all

vars i , hi, lo : Integer; begin i := 12345678; // 0x00BC614E hi := i.Binary[3:2].Integer; lo := i.Binary[1:2].Integer; write i.Binary.display; // 4E61 BC00 write lo.Binary.display; // 4E61 0000 write hi.Binary.display; // BC00 0000 end;