is there a bit twiddling library?  you should start one and i'll happily 
import it (for CRC those are completely outside the main loop - for 
checksums that require the input bits to be reversed the standard approach 
is to reverse **everything else** - it's very cute :o)  cheers, andrew

On Sunday, 20 April 2014 18:42:33 UTC-3, Laszlo Hars wrote:
>
> COOL!
>
> A little side note: some parts can still be tweaked. E.g. the function 
> reflect_bits(). Here are a few variations, although they don't affect the 
> running time:
> ~~~
> function reflect1(n::Uint8) # Two '&' operators and some parentheses 
> removed
>     n = n >>> 4 | n << 4
>     n = (n & 0xcc) >>> 2 | (n & 0x33) << 2
>     n & 0xaa >>> 1 | n & 0x55 << 1
> end
>
> r4 = uint8([0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15])
> function reflect2(n::Uint8) # 4-bit lookup table (if 8-bit table is too 
> large)
>     r4[n>>>4+1] | r4[(n&15)+1]<<4
> end
>
> function reflect3(n::Uint8) # Building up the reverse bit-by-bit
>     r = zero(Uint8)
>     for i = 0:7
>         r = r<<1 | (n>>>i)&1
>     end
>     r
> end
>
> function reflect4(n::Uint8) # Bits put together, no assignment
>     n&1<<7 | (n>>>1)&1<<6 | (n>>>2)&1<<5 | (n>>>3)&1<<4 |
>     (n>>>4)&1<<3 | (n>>>5)&1<<2 | (n>>>6)&1<<1 | n>>>7
> end
> ~~~
>

Reply via email to