-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_bitwise.h
43 lines (35 loc) · 1.55 KB
/
ft_bitwise.h
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bitwise.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rvandepu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/28 13:33:28 by rvandepu #+# #+# */
/* Updated: 2024/01/28 14:26:30 by rvandepu ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_BITWISE_H
# define FT_BITWISE_H
# include <stdbool.h>
inline unsigned int ft_bit_set(unsigned int number, unsigned int n)
{
return (number | ((unsigned int)1 << n));
}
inline unsigned int ft_bit_clear(unsigned int number, unsigned int n)
{
return (number & ~((unsigned int)1 << n));
}
inline unsigned int ft_bit_toggle(unsigned int number, unsigned int n)
{
return (number ^ ((unsigned int)1 << n));
}
inline bool ft_bit_check(unsigned int number, unsigned int n)
{
return ((number >> n) & (unsigned int)1);
}
inline unsigned int ft_bit_set_to(unsigned int number, unsigned int n, bool x)
{
return ((number & ~((unsigned int)1 << n)) | ((unsigned int)x << n));
}
#endif