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

→‎Errors: comparison.
(→‎Errors: new section)
(→‎Errors: comparison.)
Line 85:
 
The Algol 68 example though, I cannot see how those figures (especially the LSB) could possibly be correct on a machine that uses binary digits. They are just wildly off. I don't know ''exactly'' what's wrong, but I truly don't believe them. Or are they counting from the other end? That'd just be weird given that virtually everyone numbers bits from the LSB, as that gives consistent answers for small integers irrespective of the size of machine integers being used. –[[User:Dkf|Donal Fellows]] 09:01, 8 December 2011 (UTC)
 
Compare:
* C's '''unsigned''' has the '''bits''' organised right to left, but - IIRC - not numbered in any way.
** The numbering is "virtual" depending on whether << or >> is used to extract the bit.
** Maybe C's closest "ordering" concept would be: <lang c>struct {signed int a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1;} ordered;</lang>
*** IIRC this won't work: <lang c>struct {signed int bits:1[32];} ordered;</lang>
** In particular unsigned '''bits''' (or unsigned) cannot ever be <u>coerced</u> to a '''bool''' array.
** There is no need or use in an actual number or index to the '''bits'''.
* Algol68 has two places where the bit number/index is used:
** '''elem''' operator, eg x '''elem''' 1 give the "first" bit of x, which is the bit on the extreme left.
** When a '''bits''' variable (eg x) is coerced to a '''bool''' array - []'''bool'''(x) - again the "first" bool - x[1] - is the extreme left bit.
** One nice effect is x[LWB x:UPB x] would exactly extract the non-zero bits 2r11101101 of 2r0000000111011010000
* Weirdly, when a short '''bits''' literal e.g. '''bits''' x:=2r11101101 is assigned into the '''bits''' variable x, it is padded to the <u>left</u> 24 with zeros and become 2r0000000000000000000011101101! i.e <u>right</u> justified just like C!
* '''shl''' and '''shr''' work the same as C's << and >>
[[User:NevilleDNZ|NevilleDNZ]] 12:01, 8 December 2011 (UTC)