in reply to reliable get position of leftmost bit in large integers
Should your code not be:
perl -e 'for my $i (1..63) {if(int(log(2**($i-1))/log(2)) != $i-1) {pr +int "$i\n"}}'
which gives no output for me.
UPDATE: Apologies, I think I get it now, the leading one of 2^i - 1 should be in the same place as the leading one for 2^(i-1) which is what you are testing.
My next thought was to use length(sprintf("%b",$x)) but that does not work either:
for my $i (1..63) { if(length(sprintf("%b",2**$i-1)) != length(sprintf("%b",2**($i-1)) +)) { print"$i\n"; printf("%b\n",2**($i-1)); printf("%b\n",(2**$i)-1); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: reliable get position of leftmost bit in large integers
by wollmers (Scribe) on Mar 12, 2015 at 11:09 UTC | |
by Eily (Monsignor) on Mar 12, 2015 at 13:09 UTC | |
by BrowserUk (Patriarch) on Mar 12, 2015 at 14:35 UTC |