[ create a new paste ] login | about

Link: http://codepad.org/8jOaSXH8    [ raw code | fork ]

Evetro - C, pasted on Jul 9:
/// direct method for 32-bit using bsf
unsigned rbN2 (unsigned arg)
{
  __asm
  {
    xor eax, eax  // eax := 0
    mov ebx, arg  // ebx := arg

NEXTBIT:          // loop begin
    bsf ecx, ebx  // ecx := bit_search_forward (ebx), if ebx ...
    jz EXIT       // ... == 0 then exit
    
    mov edx, 1    // edx := 1
    shl edx, cl   // edx <<= (char)ecx
    xor ebx, edx  // ebx ^= edx // reset this bit in argument
    
    neg ecx       // ecx := -ecx
    add ecx, 31   // ecx += 31  // doing cl = 31 - cl
    mov edx, 1    // edx := 1
    shl edx, cl   // edx <<= (char)ecx
    or eax, edx   // eax |= edx // set reversed bit in result

    jmp NEXTBIT   // next iteration
EXIT:
  }
  // return eax
}


Create a new paste based on this one


Comments: