-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putbits.c
executable file
·65 lines (61 loc) · 1.74 KB
/
ft_putbits.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
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putbits.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/18 10:07:24 by akharrou #+# #+# */
/* Updated: 2019/05/23 10:49:17 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** ft_putbits -- print bit representation of some data
**
** SYNOPSIS
** #include <libft.h>
**
** void
** ft_putbits(void *data, size_t size);
**
** PARAMETERS
**
** void *data Pointer to some data.
**
** size_t size Size of the data.
**
** DESCRIPTION
** Prints to standard out the bits of the pointed to data.
**
** RETURN VALUES
** None.
*/
#include "../Includes/stdio_42.h"
#include "../Includes/stdint_42.h"
void ft_putbits(void *data, size_t size)
{
uint8_t *bytestr;
uint8_t bit;
size_t i;
size_t j;
size_t k;
bytestr = (uint8_t *)(data);
i = 0;
k = size - 1;
while (i < size)
{
j = 0;
while (j < 8)
{
bit = (uint8_t)(bytestr[k] & (1 << (7 - j)));
ft_putchar(((bit) ? '1' : '0'));
++j;
}
--k;
++i;
if (i < size)
ft_putchar(' ');
}
return ;
}