I'm making a remake of the game Elite from 1984 and I'm cloning it's universe generation method which uses hexadecimal numbers and bit operations. Is this possible in Ti-Basic? By bit operations I mean things like shifting («, »).
TI-BASIC is a Turing Complete language, so you can always make it emulate those operations :P
But no, they are not expressly supported, so you do actually need to emulate them. I don't know how familiar you are with the math behind those operations, but a left shift n times is equivalent to multiplying the number by 2n and a right shift is division with truncation of the fractional part. To test specific bits, I was pretty sure that we had a routine for that somewhere, but here is one that should work to test bit N of X:
.5≤fPart(.5X2^-N
Also, be careful not to try to over-emulate. A lot of routines that you might need to rewrite might have a very simple BASIC function. For example, if you wanted to emulate the following, where 'c' refers to an carry flag:
0→A
While X≠0
X>>1→X
If c=1
A+Y→Y
Y<<1→Y
EndWhile
That can be optimised in BASIC to:
X*Y→A
Z80 Assembly>English>TI-BASIC>Python>French>C>0
I have a question just by interest.
I understand the left shift n times being equivalent to multiplying with 2^n, but I do not understand the right shift:
a right shift is division with truncation of the fractional part
I live in Germany, so I thought I would not understand because of my English. But I researched the word truncation, but I do not understand it
Wake me, when you need me.
A right shift is:
Divide by 2.
Remove the fractional part by taking an int( of it or subtracting the fPart( from it. Basically, always round down. It is covered in Xeda's code.
Truncation, by my best understanding, is "chopping off" digits.
Thank you for explaining :)
Wake me, when you need me.