Difference between revisions of "$isbit"

From Scriptwiki
Jump to: navigation, search
(added category)
m
 
Line 21: Line 21:
 
|}
 
|}
  
As you can see by the table above in the highlighted cells, if you have the value 13 it requires the 1st, 3rd and 4th bit to be turned on.
+
As you can see by the table above in the highlighted cells, if you have the decimal 13 it requires the 1st, 3rd and 4th bit to be turned on. (See [[$base]] for information on converting decimal to binary)
 
How we figure this out, is we take the 1st, 3rd and 4th bit and add them together 1+4+8 and this gives a value of 13.
 
How we figure this out, is we take the 1st, 3rd and 4th bit and add them together 1+4+8 and this gives a value of 13.
 
Using the bits values 1,2,4,8 and 16 in this example it is impossible to get to 13 other than using 1,4 and 8.
 
Using the bits values 1,2,4,8 and 16 in this example it is impossible to get to 13 other than using 1,4 and 8.
Line 41: Line 41:
 
*[[$xor]]
 
*[[$xor]]
  
[[Category:Text and Number Identifiers]]
+
[[Category:Text and Number Identifiers]] [[Category:Bitwise Identifiers]]

Latest revision as of 20:36, 10 May 2008

Returns 1 if the Nth bit in number A is turned on, otherwise 0 will be returned.

$isbit(A,N)


In the table below is information about bits, values and their binary representation

As you can see by the table above in the highlighted cells, if you have the decimal 13 it requires the 1st, 3rd and 4th bit to be turned on. (See $base for information on converting decimal to binary) How we figure this out, is we take the 1st, 3rd and 4th bit and add them together 1+4+8 and this gives a value of 13. Using the bits values 1,2,4,8 and 16 in this example it is impossible to get to 13 other than using 1,4 and 8. This can be seen in the example below.

Examples

var %i = 1 
while (%i <= 13) {
  echo -ag %i bit is $iif($isbit(13,%i),On,Off) 
  inc %i
}

See also