Versatile remote IO design


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3319
Posted: 08:49am 09 Jul 2025      

If a 32 bit integer has been loaded into a 64 bit integer variable n%, the sign bit at bit 31 can be shifted up 32 then bit 31 erased.
> n%=4095 : inc n%, 2^31 :? bin$(n%,64) 'make a 32bit negative number
0000000000000000000000000000000010000000000000000000111111111111
> inc n%, (n% and 2^31)<<32 :? bin$(n%,64)  'upshift the sign
1000000000000000000000000000000010000000000000000000111111111111
> n% = n% and ((2^31 -1) + 2^63) :? bin$(n%,64) 'erase old sign
1000000000000000000000000000000000000000000000000000111111111111
>

Edited 2025-07-09 19:00 by phil99