小编Wic*_*Sec的帖子

切换位,但不切换回来?

我正在搞乱一些代码并决定尝试在文件中切换一些位,然后将它们切换回来获取原始文件.不知何故,它改变了位,但不会改变它们.

这是我有的:

魔术发生在我打开文件并进入rByte [0]和rByte [1].

unsigned char rByte[] = {0, 0};

int isBitSet(unsigned char byte, int bytePosition){

    unsigned char mask[] = {128, 64, 32, 16, 8, 4, 2, 1};
    return ( (byte & mask[bytePosition]) != 0 );
}

unsigned char setBit(unsigned char byte, int pos) {
    byte |= (0x01 << pos);
    return byte;
}

unsigned char clearBit(unsigned char byte, int pos){
    byte &= ~(0x01 << pos);
    return byte;
}

/* DO NOT TOUCH */

void switchBits (unsigned char byte1, unsigned …
Run Code Online (Sandbox Code Playgroud)

c bit switching

0
推荐指数
1
解决办法
98
查看次数

标签 统计

bit ×1

c ×1

switching ×1