42_push_swap/ft_bitlen.c

30 lines
1.1 KiB
C
Raw Permalink Normal View History

2022-11-23 15:44:27 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
2022-12-06 11:35:45 -05:00
/* ft_bitlen.c :+: :+: :+: */
2022-11-23 15:44:27 -05:00
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
2022-12-06 11:35:45 -05:00
/* Created: 2022/12/06 13:25:38 by cchauvet #+# #+# */
/* Updated: 2022/12/06 13:28:14 by cchauvet ### ########.fr */
2022-11-23 15:44:27 -05:00
/* */
/* ************************************************************************** */
#include "pushswap.h"
2022-12-06 11:35:45 -05:00
unsigned int ft_bitlen(unsigned int nb)
2022-11-23 15:44:27 -05:00
{
2022-12-06 11:35:45 -05:00
unsigned int i;
unsigned int y;
2022-11-23 15:44:27 -05:00
2022-12-06 11:35:45 -05:00
i = 0;
y = 0;
while (i < sizeof(unsigned int) * 8)
2022-11-23 15:44:27 -05:00
{
2022-12-06 11:35:45 -05:00
if (nb >> i & 1)
y = i;
2022-11-23 15:44:27 -05:00
i++;
}
2022-12-06 11:35:45 -05:00
return (y);
2022-11-23 15:44:27 -05:00
}