42_push_swap/ft_bit_finder.c
2022-11-30 13:21:32 +01:00

35 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bit_finder.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/23 17:31:10 by cchauvet #+# #+# */
/* Updated: 2022/11/29 15:06:00 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
int ft_bit_finder_left(int big, int tofind)
{
int i;
i = (int) sizeof(int) * 8 - 1;
while (i != 0 && ((big >> i) & 1) != tofind)
i--;
return (sizeof(int) * 8 - i - 1);
}
int ft_bit_finder_right(int big, int tofind)
{
int i;
i = 0;
while (i != ((int) sizeof(int) * 8 - 1) && ((big << i) & 1) != tofind)
i++;
return (i);
}