내장 함수

실측치 내장 함수는 십진수 1의 수를 계산하는데 사용될 수있다; 되돌아 수가 홀수 또는 짝수이다 반환 번호 0의 ​​시작, 끝에서 0의 수를 반환한다.

참고 링크 :

// C 프로그램 _builtin_popcount을 설명하기 (X) 

#INCLUDE <STDIO.H> 
 INT ) (주 
{ 
    INT N = 5 ; 
    인 printf ( " % D의 이진수 1의 카운트가 % d하다 " , 
        N, __builtin_popcount (N)); 
    반환  0 ; 
}

// C 프로그램 _builtin_parity을 설명하기 (X) 

#INCLUDE <STDIO.H> 
 INT ) (주 
{ 
    INT N = 7 ; 
    인 printf ( " % D의 패리티가 % d하다 " , 
        N, __builtin_parity (N)); 
    반환  0 ; 
}

상기 제 2 기능 _builtin_parity (X)를 계산한다 : 여기서 x는 홀수 숫자의 수가 리턴 달리 0이다.

// C 프로그램 __builtin_clz을 설명하기 (X) 
#INCLUDE <STDIO.H> INT ) (주 
{ INT N = 16 ; 
    인 printf ( " % d의 1 이전의 선행 제로 카운트가 % d하다 " , 
        N, __builtin_clz (N)); 반환 0 ; 
}

    
     

// C program to illustrate __builtin_ctz(x) 
#include <stdio.h> 
int main() 
{ 
    int n = 16; 
    printf("Count of zeros from last to first "
        "occurrence of one is %d", 
        __builtin_ctz(n)); 
    return 0; 
} 

// C program to illustrate builtin functions of 
// GCC compiler 
#include <stdio.h> 
#include <stdlib.h> 

int main() 
{ 
    int num = 4; 
    int clz = 0; 
    int ctz = 0; 
    int pop = 0; 
    int parity = 0; 

    pop = __builtin_popcount(num); 
    printf("Number of one's in %d is %d\n", num, pop); 

    parity = __builtin_parity(num); 
    printf("Parity of %d is %d\n", num, parity); 

    clz = __builtin_clz(num); 
    printf("Number of leading zero's in %d is %d\n", num, clz); 

    // It only works for unsigned values 
    clz = __builtin_clz(-num); 
    printf("Number of leading zero's in %d is %d\n", -num, clz); 

    ctz = __builtin_ctz(num); 
    printf("Number of trailing zero's in %d is %d\n", num, ctz); 

    return 0; 
} 

 

추천

출처www.cnblogs.com/Bella2017/p/11282035.html