Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: macweirdo on November 27, 2011, 01:08:51 pm
-
Alright, so I want to read, for example, a single bit of data from a byte.
I tried (L3+offset) and 2 to the power of bit_I_want
where L3+offset is my byte of choice and "and" is logical and
but I can't figure out how to get # to the power of other# because ^ is now modulus.
So tl;dr how do you read a bit from a byte and how do you multiply a number by itself many times without using For(?
Thanks in advance :D
-
To read a bit from a byte, use the Euler's e.
From the Axe documentation:
EXP1eEXP2
Gets the expression2-th bit of the 8-bit number in expression1. Unlike assembly, the leftmost bit (high order) is bit 0 and the rightmost bit (low order) is bit 7. The bit checking is modular. That's the Euler's constant "e".
So if we have
9->{L1+1} .In bits, 0000 1001
For(A,0,7)
Text(A*8,10,Ae{L1+1}>Dec)
End
...The screen would display something like
0 0 0 0 1 0 0 1
The '^2' (the small exponent 2 token) can multiply a number by itself once, and 'e^(' (e to the power of token) can multiply two to a given power, but I can't seem to find anything about actual exponents in the documentation (unless I'm being stupid). Hmm...
-
A function to get the power of a number would be pretty easy to make, if there isn't one handy.
Here's a C++ function; I don't know Axe:
double Pow(double number,double power)
{
for (power;power>0;power--)
number*=number;
return number
}
-
A function to get the power of a number would be pretty easy to make, if there isn't one handy.
Here's a C++ function; I don't know Axe:
double Pow(double number,double power)
{
for (power;power>0;power--)
number*=number;
return number
}
O(log n) instead of O(n) :D
double Pow(double number,double power)
{
result = 1
for (power;power>0;power>>=1) {
if (power % 2)
result *= number;
number*=number;
}
return result;
}
-
Or exp(ln(base) * power), which actually handles non-integral powers instead of just pretending to do so but then blowing its cover by bitshifting a double ;)
-
Yeah, I'm pretty sure he meant the second argument to be an unsigned int :P
Anyway, Axe equivalent:
Lbl POW
1→r3
r2
While 1
If ^2
r3*r1→r3
End
r1²→r1
End!If r2/2→r2
Return r3
-
Thanks guys!
Also, if you're really looking to get the exponent of a number, and you're really just doing 2^$something,
just bitshift 1 $something times.
I just don't like looping :(
EDIT: or wait, no
0010 is 2
0100 is 4
nvm, don't even need loops for that