I think this code:
:D→B :0 // this will make sure that if I is greater than the highest index, 0 will be returned :If D:Then //log(0) would give domain error, and 0d=0b. :For(A,1+int(log(D)/log(2)),I,-1) //A will run through the indexes, from high to low stopping at I(the one we needed). log(D)/log(2) = base 2 log of D :0 :If 2^A≥B: Then :B-2^A→B :1 End:End:End
Could be shortened to this for most scenarios:
For example, to test bit 2 of the value 18:
and 18=10010b, which fits. Testing bit 4:
I am not sure how much accuracy it will retain for very large numbers, though, so you will probably need to do a check if I>32 or something.
EDIT: I often use this short routine for testing bits when I don't want to actually convert a number to binary. For example, with the routine I posted for raising A^K mod M, I used this to test the bits in K.
47%? Take a look and try to imagine how cool 100% will be. This has won zContest 2011 and made news on TICalc. This compromise between Assembly and BASIC parses like BASIC and is fast like assembly. Grammer 2