??? 12/20/06 17:25 Modified: 12/20/06 17:26 Read: times |
#129834 - It looks interesting .. Responding to: ???'s previous message |
... however, I haven't tried it yet. Mostly because my current solution seems simples - all it needs to do is count the zeros at the LSB end, find the first zero after the block of zeros at the LSB end, and do some shifting and boolean operations with a mask.
i.e.: If all zeros are on the lsb end, move them to the msb end and add one zero. Example: 1111 1111 1000 0000 -> 0000 0000 1111 1111 Else (Example): Input value: 1111 1001 0111 1000 ^ ^^^ | +-- Y = 3 trailing zeros +--------- second block of zeros at bit position Z = 8 1. Move Y trailing zeros to position Z - 2, pad with ones 1111 1001 0100 0111 ^^ ^^^^ 2. XOR with (0000 0000 0000 0011 << Z - 2) 1111 1001 1000 0111 ^^ |