-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_bit_manipulation.c
50 lines (40 loc) · 1.32 KB
/
ft_bit_manipulation.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bit_manipulation.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rabustam <rabustam@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/14 19:25:13 by rabustam #+# #+# */
/* Updated: 2022/10/25 19:05:31 by rabustam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_clear_bit(int c, int position)
{
int mask;
mask = 1 << position;
return (c & ~mask);
}
int ft_set_bit(int c, int position)
{
int mask;
mask = 1 << position;
return (c | mask);
}
int ft_flip_bit(int c, int position)
{
int mask;
mask = 1 << position;
return (c ^ mask);
}
int ft_is_bit_set(int c, int position)
{
int shifted;
shifted = c >> position;
return (shifted & 1);
}
int ft_is_odd(int c)
{
return (c & 1);
}