Skip to content

Commit 6b8a53d

Browse files
dop42Luis Mouta Guedes SilvaCopilot
authored
feat(bit): get bit function (#12)
* feat(bit): get bit function * Update src/ft_get_bit.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/ft_get_bit.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update includes/libft.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Luis Mouta Guedes Silva <lmouta-g@f6r9s3.clusters.42paris.fr> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 52e4bd3 commit 6b8a53d

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎includes/libft.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/* ::: :::::::: */
44
/* libft.h :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: lm0uta <lmouta-g@student.42.fr> +#+ +:+ +#+ */
6+
/* By: lmouta-g <lmouta-g@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/11/12 13:48:18 by lm0uta #+# #+# */
9-
/* Updated: 2025/11/14 15:47:26 by lm0uta ### ########.fr */
9+
/* Updated: 2026/02/19 12:08:25 by lmouta-g ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -63,6 +63,8 @@ void *ft_memmove(void *dst, const void *src, size_t len);
6363
void *ft_memchr(const void *s, int c, size_t n);
6464
int ft_memcmp(const void *s1, const void *s2, size_t len);
6565
void *ft_calloc(size_t count, size_t size);
66+
int ft_get_bit(int num, int bit);
67+
6668

6769
void ft_putchar_fd(char c, int fd);
6870
void ft_putstr_fd(char *s, int fd);

‎src/ft_get_bit.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_get_bit.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: lmouta-g <lmouta-g@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2026/02/19 12:07:36 by lmouta-g #+# #+# */
9+
/* Updated: 2026/02/19 12:08:03 by lmouta-g ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "../includes/libft.h"
14+
/**
15+
* ft_get_bit - returns the value of a specific bit in an integer
16+
* @num: the number from which to extract the bit
17+
* @bit: position of the bit to get (starting from the right, 0-based)
18+
* Return: 0 if the bit is 0, 1 if the bit is 1
19+
*/
20+
int ft_get_bit(int num, int bit)
21+
{
22+
return ((num >> bit) & 1);
23+
}

0 commit comments

Comments
 (0)