TIB: a way to test for bits


[Prev][Next][Index][Thread]

TIB: a way to test for bits




> > And can you read individual bits of an integer (like
> > asm)? For example: 
> > read 150 as 10010110 and take each bit a put it in matrix.
> 
> It's possible but not easy.  I am not sure the best way to do
> it, but I'm sure someone on this list knows a few tricks.

I figured out a way to test for bits.  It couldn't be easier!!!
mod(int (number/base^bit),bit


Example:  If you want to know what the 3 bit of 150 is in
binary numbers.

mod(int (150/2^2),2

Example2  If you want to know what the 4th digit is of 23453 in base 10.
mod(int (23453/10^3),10
or the 2nd digit
mod(int (23453/10^1),10

this couldn't be easier!!!

To put bits into the number N:

to put 1 into bit 3
N+1*2^2->N
to put 1 into bit 5
N+1*2^4->N
to take out bit 2 if it is set.
N-1*2^1->N
to put 0 into anything, do nothing.

You might have to put an if statement for things to come out
right.  Ex: to see if bit 5 is set and if it is, reset it.
:if mod(int (N/2^4),2)==1
:then
:N-1*2^4->N 
:else
:goto next
:end


Hope this helps.
==
Garth Johnson
Please email me at garthjohnson@bigfoot.com
 or brandtly@hotmail.com for large files

Visit my website!
http://www.bigfoot.com/~garthjohnson

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com