用2個32位的整型數表示64個埠的點陣圖
阿新 • • 發佈:2018-11-11
#include <stdio.h> #define OFDPA_PBMP_ITER(bm, port) \ int i = 0, p = 0; \ for ((p) = 0, port=1; (p) < 64; (p)++, i=(p)/32, port=p+1) \ if ((((bm[i]) >> (p)) & 1) != 0 ) #define OFDPA_PBMP_ADD(bm, port) \ if (port > 32) { \ (bm[1]) |= 1 << (((port)-1)%32) ; \ } else \ (bm[0]) |= 1 << ((port)-1) int main() { int pbmp[2]={0}; int port; OFDPA_PBMP_ADD(pbmp, 2); OFDPA_PBMP_ADD(pbmp, 63); OFDPA_PBMP_ADD(pbmp, 32); //OFDPA_PBMP_ADD(pbmp, 1); OFDPA_PBMP_ITER(pbmp, port) { printf("0x%08X 0x%08X => %d \n", pbmp[1], pbmp[0], port); } return 0; }