'===========================================================================
' Subject: FULL 16-BIT SHIFTING ROUTINE       Date: 12-08-96 (13:50)       
'  Author: Kurt Kuzba                         Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: BINARY.ABC
'===========================================================================
'>   I would like to know if anyone knows a simple right bit-
'>   shift routine for QBasic.
'>......
'   I wrote one of those a while ago when someone posted a PB
'program using SHIFT(). I recently stumbled across a means to
'accurately convert bit patterns for INTEGER values to LONG when
'the value is negative, so I did an update to the process.
'It now allows a full 16-bit shift where it only allowed 15 before.

'_|_|_|   SHIFT.BAS
'_|_|_|   A simple bit-shifting routine for Qbasic
'_|_|_|   No warrantee or guarantee is given or implied.
'_|_|_|   Released   PUBLIC DOMAIN   by Kurt Kuzba.  (12/7/96)
DECLARE FUNCTION shift% (D%, V%, T%)
DO
   INPUT "number => ", N%
   sh% = N%
   PRINT shift%(0, sh%, 1), shift%(1, sh%, 1)
LOOP WHILE N% > 0
END
FUNCTION shift% (D%, V%, T%)
   '_|_|_|   A simple bit-shifting routine for Qbasic
   '_|_|_|   shift V% right or left T% places
   '_|_|_|   if D% = 0 then shift right, else shift left
   S& = V%
   IF S& < 0 THEN S& = 65536 + S&
   FOR T% = T% TO 1 STEP -1
      IF D% = 0 THEN
         S& = S& \ 2
      ELSE
         S& = (S& * 2) AND 65535
      END IF
   NEXT
   IF S& > 32767 THEN S& = S& - 65536
   shift% = S&
END FUNCTION
'_|_|_|   end   SHIFT.BAS
