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 ?
最佳答案
>>
是按位右移运算符。
X >>= N
相当于
X = X >> N
一些例子:
- (4 >> 1) = (0100b >> 1) = 0010b = 2
- (12 >> 2) = (1100b >> 2) = 0011b = 3
关于c - 如何理解程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30680333/