Skip to content

Instantly share code, notes, and snippets.

@emiflake
Created March 5, 2019 21:58
Show Gist options
  • Save emiflake/f67dfe8099668ecb77cd23b59d1cfa79 to your computer and use it in GitHub Desktop.
Save emiflake/f67dfe8099668ecb77cd23b59d1cfa79 to your computer and use it in GitHub Desktop.
#include <stdio.h>
unsigned char swap_bits(unsigned char octet)
{
return (octet >> 4) | (octet << 4);
}
int main()
{
unsigned char a = 10;
a = swap_bits(a);
char i = sizeof(unsigned char) * 8; // 8
/*
00001010 10
00000100 1 << 2
& 00000000
00000001 1 << 0
00000010 1 << 1
00000100 1 << 2
00001000 1 << 3
00010000 1 << 4
00100000 1 << 5
01000000 1 << 6
10000000 1 << 7
*/
/*
00001010
00000000 >> 4
10100000 << 4
00000000
10100000
| 10100000
*/
while (i > 0)
{
// printf("%d\n", 0 != (a & (1 << i)));
putchar('0' + (0 != (a & (1 << (i - 1)))));
i--;
}
putchar('\n');
return (0);
}
/*
** i want pancakes!!!!NOOOOO
** BUT WHY!!!!!!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment