Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void printBits(unsigned x) {
- for (int i = sizeof(x) * 8 - 1; i >= 0; i--) {
- printf("%d", 1 & (x >> i));
- if (i % 4 == 0) {
- putchar(' ');
- }
- }
- puts("");
- }
- unsigned char pack(unsigned a, unsigned b) {
- unsigned char r = 0;
- r |= a;
- r |= (b << 4);
- return r;
- }
- void unpack(unsigned char ch) {
- unsigned mask = (1 << 4) - 1;
- unsigned fi = mask & ch;
- unsigned se = mask & (ch >> 4);
- printf("%u\n%u\n", fi, se);
- }
- int main(void) {
- unsigned a, b;
- scanf("%u", &a);
- scanf("%u", &b);
- printBits(a);
- printBits(b);
- unsigned char ch = pack(a, b);
- printBits(ch);
- unpack(ch);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement