Find first and last set bit of a long integer: Difference between revisions
Find first and last set bit of a long integer (view source)
Revision as of 11:07, 11 October 2022
, 1 year agoput Quackery entry in correct alphabetic order. D'oh.
(Added Quackery.) |
m (put Quackery entry in correct alphabetic order. D'oh.) |
||
Line 1,609:
3741579015304032 MSB: 51 LSB: 5
</pre>
=={{header|Racket}}==▼
<syntaxhighlight lang="racket">▼
#lang racket▼
(require rnrs/arithmetic/bitwise-6)▼
(for/list ([n 20])▼
(define x (expt 42 n))▼
(list n (bitwise-first-bit-set x) (- (integer-length x) 1)))▼
</syntaxhighlight>▼
{{out}}▼
<syntaxhighlight lang="racket">▼
'((0 0 0)▼
(1 1 5)▼
(2 2 10)▼
(3 3 16)▼
(4 4 21)▼
(5 5 26)▼
(6 6 32)▼
(7 7 37)▼
(8 8 43)▼
(9 9 48)▼
(10 10 53)▼
(11 11 59)▼
(12 12 64)▼
(13 13 70)▼
(14 14 75)▼
(15 15 80)▼
(16 16 86)▼
(17 17 91)▼
(18 18 97)▼
(19 19 102))▼
</syntaxhighlight>▼
=={{header|Quackery}}==
Line 1,697 ⟶ 1,665:
2873716601616 msb:41 lsb:4
3741579015304032 msb:51 lsb:5</pre>
▲=={{header|Racket}}==
▲<syntaxhighlight lang="racket">
▲#lang racket
▲(require rnrs/arithmetic/bitwise-6)
▲(for/list ([n 20])
▲ (define x (expt 42 n))
▲ (list n (bitwise-first-bit-set x) (- (integer-length x) 1)))
▲</syntaxhighlight>
▲{{out}}
▲<syntaxhighlight lang="racket">
▲'((0 0 0)
▲ (1 1 5)
▲ (2 2 10)
▲ (3 3 16)
▲ (4 4 21)
▲ (5 5 26)
▲ (6 6 32)
▲ (7 7 37)
▲ (8 8 43)
▲ (9 9 48)
▲ (10 10 53)
▲ (11 11 59)
▲ (12 12 64)
▲ (13 13 70)
▲ (14 14 75)
▲ (15 15 80)
▲ (16 16 86)
▲ (17 17 91)
▲ (18 18 97)
▲ (19 19 102))
▲</syntaxhighlight>
=={{header|Raku}}==
|