int mask = 0700, N_BITS = 3;
struct stat buff;
static char perm[] = {"---", "--x", "-w-", "-w x", "r--", "r-x", "rw-", "rwx"};
stat(f_d, &buff); //get the permissions info of file
printf("%3s", perm[buff.st_mode & mask >> (i - 1) * N_BITS)] //HOW TO UNDERSTAND ?`
mask >>= N_BITS; //HOW TO UNDERSTAND ?
答案 0 :(得分:1)
>>
是按位右移运算符。
X >>= N
相当于
X = X >> N
一些例子:
答案 1 :(得分:1)
>>
是bitwise right shift operator
mask>>=N_BITS
相当于mask = mask >> N_BITS
所以最初
mask = 0b111000000;
N_BITS
操作后mask>>=N_BITS
等于 3
mask = 0b000111000;