[squeak-dev] The Trunk: Kernel-cmm.568.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Apr 12 06:20:24 UTC 2011


Bit by bit ?
I suggest using
http://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
reverse next power of two bits, then bitShift: the difference...

Or someone else will exhibit a bitBlt hack :)

Nicolas

2011/4/12  <commits at source.squeak.org>:
> Chris Muller uploaded a new version of Kernel to project The Trunk:
> http://source.squeak.org/trunk/Kernel-cmm.568.mcz
>
> ==================== Summary ====================
>
> Name: Kernel-cmm.568
> Author: cmm
> Time: 11 April 2011, 9:01:09.858 pm
> UUID: 340ecdd9-40de-42e4-8388-09abc07cdedf
> Ancestors: Kernel-nice.567
>
> Added Integer>>bitReverse:.
>
> =============== Diff against Kernel-nice.567 ===============
>
> Item was added:
> + ----- Method: Integer>>bitReverse: (in category 'bit manipulation') -----
> + bitReverse: highBit
> +       "Reverse the bits of the receiver so that the lsb is the highBit'th bit of the answer.  Translated from C code at:  http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious."
> +       | v r s |
> +       highBit < self highBit ifTrue: [ self error: 'Not enough bits.' ].
> +       v := self.
> +       r := v bitAnd: 1.
> +       s := highBit - 1.
> +       [ v := v bitShift: -1.
> +       v = 0 ] whileFalse:
> +               [ r := r bitShift: 1.
> +               r := r bitOr: (v bitAnd: 1).
> +               s := s - 1 ].
> +       ^ r bitShift: s!
>
>
>



More information about the Squeak-dev mailing list