Re: Rotating bits left in BASIC



In article <4e635977ffa.m.conroy@xxxxxxxxxxxx>,
Andrew Conroy <a.m.conroy@xxxxxxxxxxxx> wrote:

Moving on from here, I've now realised that the numbers I'm working with
are stupidly large and will be bigger than &7fffffff (in fact bigger than
&7fffffff*2), and so are, I guess, effectively 64bit numbers rather than
the more usual 32bit ones. This leads to two problems:
1) How do I rotate 64bit numbers?
see below

2) How do I do things like finding the integer parts of 64bit numbers?
INT reports "Number too big" as does trying to put them into integer
variables.
On a related note, I've noticed that (&7fffffff*2) gives a different
result to (&7fffffff+&7fffffff). 4294967294

In a task window I get
*BASIC
P. &7fffffff * 2
4.29496729E9
^ so the conversion has been promoted to a floating
point which is capable of holding the result.

P. &7fffffff + &7fffffff
-2
This is because integers are using signed maths ie bit 31 is the sign (a 1
makes the number negative ) so -1 + -1 = -2 is correct.

A 32bit binary no. will hold 4294967295 as a max no but using the top bit
as a sign reduces this this to a range of something like
-2147483648 and +2147483647

ASAIK BASIC has no direct provision for 64 bit integers, BASIC 64 I 'guess'
allows 64 bit floating point numbers but you would still lose precision as
with BASIC's normal (40 I think) bit size.

What you could do is use two (32 bit) memory locations next to each other
and do all your maths using 'binary' techniques or use 64bit assembler
opcodes on those locations if they are available.

I think there are couple of OS calls to print out large numbers (that would
be used by he filer etc) to display 64 bit nos, but I can't just think what
they are ATM.

to rotate 64 bits in memory imagine two 32bit words next to each other.The
sign would still be on the left ie
|--------- 1 mem location -------------------| |---------- 2ndoc-----
10001111 11111111 11111111 11111111 00000000 00000000 00000000 00000000
^sign (if used as such) 1>1

so in BASIC to rotate right, rotate both numbers right BUT you have to move
the bottom bit of the left word into the top of the right IYSWIM

HTH a little

Mitch

--
terminal_crazy@xxxxxxxxxxxxxxxxxxxxxxxxx
.