Topic : The GFA-Basic Compendium Author : GFA Systemtechnik GmbH Version : GFABasic.HYP v2.98 (12/31/2023) Subject : Documentation/Programming Nodes : 899 Index Size : 28056 HCP-Version : 3 Compiled on : Atari @charset : atarist @lang : @default : Document not found @help : Help @options : +g -i -s +z @width : 75 @hostname : STRNGSRV @hostname : CAB @hostname : HIGHWIRE @hostname : THING View Ref-FileSHL|(x,y) SHL&(x,y) SHL(x y) SHR|(x,y) SHR&(x,y) SHR(x,y) ROL|(x,y) ROL&(x,y) ROL(x,y) ROR|(x,y) ROR&(x,y) ROR(x,y) x, y: iexp These instructions SHift or ROtate the numerical expression x by y bits. If the variable type is not specified this will occur over long word length (4 bytes). If word length is specified (with &), the operation takes place over 2 bytes, and with byte length (|) over one byte. The third letter of the function name specifies the direction for the shift, 'L' standing for left, and 'R' for right. With word-length operations (with &) bit 15 is copied to bits 16 to 31, thus preserving the sign. With byte-length operations bits 8 to 31 are set to 0. The following tables show the effect of the shift instructions: x% SHL|(x%,1) BIN$(x%,16) BIN$(SHL|(x%,1),16) 18 36 00000000 00010010 00000000 00100100 642 4 00000010 10000010 00000000 00000100 x% SHL&(x%,1) BIN$(x%,16) BIN$(SHL&(x%,1),16) 18 36 00000000 00010010 00000000 00100100 130 260 00000000 10000010 00000001 00000100 x% SHR&(x%,2) BIN$(x%,16) BIN$(SHR&(x%,2),16) 24 6 00000000 00011000 00000000 00000110 4162 1040 00010000 01000010 00000100 00010000 Note: The bit representations have been grouped as two sets of 8 bits for the sake of clarity. BIN$() does not do this. The next examples concern rotation. Here, bits which leave one end of the argument are pushed in again at the other end. For instance, if only the highest bit of a byte is set, and the byte is then shifted one bit to the left (ROL|(128,1)), the set bit which disappears off the left end is re-introduced on the right as bit 0. With a shift to the left, (say SHL|(128,1)) the set bit would have been lost, with bit 0 being made zero. Examples of rotation are: x| ROL|(x|,1) BIN$(x|,1) BIN$(ROL|(x|,1),8) 6 12 00000110 00001100 130 5 10000010 00000101 x| ROR|(x|,3) BIN$(x|,8) BIN$(ROR|(x|,3),8) 66 72 01000010 01001000 2 64 00000010 01000000 Example: x|=128+1 !bits 7 and 0 set y%=ROR|(x|,1) !y becomes 192 PRINT SHL(y%,4),y%*2^4 PRINT SHL(ROR|(128+1,1),4) --> The number 3072 is printed three times. The function SHL(a,b) is equivalent to a*2^b, if no bit is lost off the left end of the four-byte number a. The bit-shift formulation, however, is clearly quicker. Memo: Contrary to what the manual states they do not preserve the sign.