-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_binary.c
57 lines (52 loc) · 1.59 KB
/
ft_print_binary.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_binary.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jraymond <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/30 22:56:59 by jraymond #+# #+# */
/* Updated: 2018/02/14 18:35:36 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_binary(t_printf *elem, long long binary, int size)
{
int i;
char bin[73];
int x;
x = 0;
ft_bzero(bin, 73);
i = (size * 8 - 1);
while (i >= 0)
{
if (!((i + 1) % 4))
bin[x++] = '|';
bin[x] = binary & BINARY ? '1' : '0';
i--;
x++;
}
bin[x] = '\n';
ft_handle_overflow(elem, bin, ft_strlen(bin), 2);
return (0);
}
int ft_print_ubinary(t_printf *elem, unsigned long long binary, int size)
{
int i;
char bin[73];
int x;
x = 0;
ft_bzero(bin, 73);
i = (size * 8 - 1);
while (i >= 0)
{
if (!((i + 1) % 4))
bin[x++] = '|';
bin[x] = binary & BINARY ? '1' : '0';
i--;
x++;
}
bin[x] = '\n';
ft_handle_overflow(elem, bin, ft_strlen(bin), 2);
return (0);
}