#include <stdio.h>
void byteReverse(char *c){
char temporaryByte = *c;
*c=0;
if(temporaryByte&0x01)*c|=0x80;
if(temporaryByte&0x02)*c|=0x40;
if(temporaryByte&0x04)*c|=0x20;
if(temporaryByte&0x08)*c|=0x10;
if(temporaryByte&0x10)*c|=0x08;
if(temporaryByte&0x20)*c|=0x04;
if(temporaryByte&0x40)*c|=0x02;
if(temporaryByte&0x80)*c|=0x01;
}
void printf2(char a){
char i=0;
for (;i<8;i++){
if(a&0x80>>i){
printf("1");
}else{
printf("0");
}
}
printf("\n");
}
void main (void){
char a=107;
printf("a的二进制格式显示:");
printf2(a);
byteReverse(&a);
printf("a字节反转之后的二进制显示:");
printf2(a);
}
在这里插入代码片
【C语言】字节反转
于 2023-09-16 15:24:11 首次发布