열렬히.뛰기

swap_bits

école 42 > exam02 > exam02 : part2 > swap_bits

공략법

octet >> 4 | octet << 4 를 하면 된다.

octet = 0100 0001 이면
octet >> 4 는 0000 0100
octet << 4 는 0001 0000

    0000 0100
or) 0001 0000
----------------
		0001 0100 

문제

Assignment name  : swap_bits
Expected files   : swap_bits.c
Allowed functions:
--------------------------------------------------------------------------------

Write a function that takes a byte, swaps its halves (like the example) and
returns the result.

Your function must be declared as follows:

unsigned char	swap_bits(unsigned char octet);

Example:

  1 byte
_____________
 0100 | 0001
     \ /
     / \
 0001 | 0100