Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:37 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: Signed vs. unsigned right-shift

Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 11:04pm 15 May 2021
Copy link to clipboard 
Print this post

Hi folks,

I seem to recall we got a new >>> operator at some point during the 5.07 firmware betas but it isn't covered by the manual or the inbuilt MMBasic help yet. Can anyone point me back at the original post about it as my google-fu has failed me.

Related to this I think the signed and unsigned operators are the opposite way around to BBC Basic, that should make for some fun bugs if anyone does some porting. Alas even if that is true there isn't anything obvious that can be done without breaking old MMBasic programs

Best wishes,

Tom
Edited 2021-05-16 09:10 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 11:48pm 15 May 2021
Copy link to clipboard 
Print this post

'ere 'tis

new operator for signed shift right
integervariable>>n' for unsigned shift right
integervariable>>>n' for signed shift right

Link

Bill
Keep safe. Live long and prosper.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 02:53am 16 May 2021
Copy link to clipboard 
Print this post

The CMM2 manual has the description of >> incorrect

  Quote  For a right shift any bits introduced are set to the value of the top bit (bit 63). For a left shift any bits introduced are set to zero.


The micromite manual is correct.

DIM INTEGER x, y, z, w
x = 12345
y = x << 8
z = x >> 8
w = x >>> 8 ' not all versions have this operator
PRINT "x     = ";BIN$(x,64);" ";x
PRINT "x << 8= ";BIN$(y,64);" ";y
PRINT
PRINT "x     = ";BIN$(x,64);" ";x
PRINT "x >> 8= ";BIN$(z,64);" ";z
PRINT "x >>>8= ";BIN$(w,64);" ";w
PRINT

x = &h7FFFFFFFFFFF7F
y = x << 8
z = x >> 8
w = x >>> 8
PRINT "x     = ";BIN$(x,64);" ";x
PRINT "x << 8= ";BIN$(y,64);" ";y
y = x << 9
PRINT "x << 9= ";BIN$(y,64);" ";y
PRINT
PRINT "x     = ";BIN$(x,64);" ";x
PRINT "x >> 8= ";BIN$(z,64);" ";z
PRINT "x >>>8= ";BIN$(w,64);" ";w
PRINT

x = 0-&h7FFFFFFFFFFF7F
y = x << 8
z = x >> 8
w = x >>> 8
PRINT "x     = ";BIN$(x,64);" ";x
PRINT "x << 8= ";BIN$(y,64);" ";y
y = x << 9
PRINT "x << 9= ";BIN$(y,64);" ";y
PRINT
PRINT "x     = ";BIN$(x,64);" ";x
PRINT "x >> 8= ";BIN$(z,64);" ";z
PRINT "x >>>8= ";BIN$(w,64);" ";w
PRINT

'Output:
'
'x     = 0000000000000000000000000000000000000000000000000011000000111001  12345
'x << 8= 0000000000000000000000000000000000000000001100000011100100000000  3160320
'
'x     = 0000000000000000000000000000000000000000000000000011000000111001  12345
'x >> 8= 0000000000000000000000000000000000000000000000000000000000110000  48
'x >>>8= 0000000000000000000000000000000000000000000000000000000000110000  48
'
'x     = 0000000001111111111111111111111111111111111111111111111101111111  36028797018963839
'x << 8= 0111111111111111111111111111111111111111111111110111111100000000  9223372036854742784
'x << 9= 1111111111111111111111111111111111111111111111101111111000000000 -66048
'
'x     = 0000000001111111111111111111111111111111111111111111111101111111  36028797018963839
'x >> 8= 0000000000000000011111111111111111111111111111111111111111111111  140737488355327
'x >>>8= 0000000000000000011111111111111111111111111111111111111111111111  140737488355327
'
'x     = 1111111110000000000000000000000000000000000000000000000010000001 -36028797018963839
'x << 8= 1000000000000000000000000000000000000000000000001000000100000000 -9223372036854742784
'x << 9= 0000000000000000000000000000000000000000000000010000001000000000  66048
'
'x     = 1111111110000000000000000000000000000000000000000000000010000001 -36028797018963839
'x >> 8= 0000000011111111100000000000000000000000000000000000000000000000  71916856549572608
'x >>>8= 1111111111111111100000000000000000000000000000000000000000000000 -140737488355328
'


Jim
VK7JH
MMedit
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025