Bitwise modulo operation Sword

/* 位运算取余操作 */

#include <stdio.h>
#include <stdlib.h> 
#include <string.h>
#include <assert.h>

void test1()
{
    unsigned a = 12;
    unsigned b = 7;
    unsigned c = 0;

    c = a % b;

    printf("----[%u]---\n", c);
}

void test2()
{
    unsigned a = 12;
    unsigned b = 32 ; 
    unsigned C = 0 ; 

    / * 
    description: 
        Bitwise modulo essential 
            requirement divisor must be a power of two 
    * / 
    C = A & (B - . 1 ); 

    the printf ( " ---- [U% ] --- \ n- " , C); 
} 

int main () 
{ 
    test2 (); 
    getchar (); 
    return  0 ; 
}

Guess you like

Origin www.cnblogs.com/zhanggaofeng/p/11891961.html