-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_print_char_bits.c
30 lines (27 loc) · 1.18 KB
/
ft_print_char_bits.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_char_bits.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aelphias <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/25 12:43:25 by aelphias #+# #+# */
/* Updated: 2019/12/25 13:14:07 by aelphias ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_print_char_bits(unsigned char ch)
{
int size;
unsigned char bit;
size = ((sizeof(unsigned char) * __CHAR_BIT__) - 1);
while (size >= 0)
{
bit = (ch & (1 << size)) == 0 ? '0' : '1';
write(1, &bit, 1);
if ((size % 8) == 0)
write(1, " ", 1);
size--;
}
write(1, "\n", 1);
}