Find first and last set bit of a long integer: Difference between revisions

Find first and last set bit of a long integer en BASIC256
(Find first and last set bit of a long integer en Yabasic)
(Find first and last set bit of a long integer en BASIC256)
Line 326:
42^10 --> First : 10 , Last : 53
42^11 --> First : 11 , Last : 59</pre>
 
 
=={{header|BASIC256}}==
<lang BASIC256>print "INT: find first & last set bit"
p = 1
for j = 0 to 5
print rjust(p,9); " "; rjust(ToBinary(p),29,0); " MSB: "; rjust(MSB(p),2); " LSB: "; rjust(LSB(p),2)
p *= 42
next j
print
end
 
function MSB(i)
return length(ToBinary(i))-1
end function
 
function LSB(i)
return (i & -i)
end function
</lang>
{{out}}
<pre>
INT: find first & last set bit
1 00000000000000000000000000001 MSB: 0 LSB: 1
42 00000000000000000000000101010 MSB: 5 LSB: 2
1764 00000000000000000011011100100 MSB: 10 LSB: 4
74088 00000000000010010000101101000 MSB: 16 LSB: 8
3111696 00000001011110111101100010000 MSB: 21 LSB: 16
130691232 00111110010100011000010100000 MSB: 26 LSB: 32
</pre>
 
 
=={{header|C}}==
2,169

edits