How can I convert a 16-bit number into 2 8-bit numbers

Quote:

> How can I split an integer into 2 addresses (high and low bytes)

> (Base is an int)

> WBlock[0] = ( Base >> 8 ) & 0xFF ;

> WBlock[1] = Base & 0xFF ;

> Thanks in advance

> Rich

Here's two functions that should do the trick.

FUNCTION HByte% (word%)

IF word% >= 0 THEN

HByte% = word% \ 256

ELSE

HByte% = (65536 + word%) \ 256

END IF

END FUNCTION

FUNCTION LByte% (word%)

IF word% >= 0 THEN

LByte% = word% MOD 256

ELSE

LByte% = (65536 + word%) MOD 256

END IF

END FUNCTION

Of course, if you know that you'll only be dealing with positive integers

less than 32767 (like a positive signed int in C) just use MOD or '\'

(integer divide). So in order to get the lowbyte value of 23456 just say

PRINT lbyte(23456)

or

PRINT 23456 MOD 256