Created
March 5, 2019 21:58
-
-
Save emiflake/f67dfe8099668ecb77cd23b59d1cfa79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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