| 12345678910111213141516171819202122232425262728293031323334353637 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* ft_itohex.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@student.42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2018/01/16 00:21:29 by bchanot #+# #+# */
- /* Updated: 2018/01/16 00:34:09 by xuser ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "libft.h"
- static void ft_itohex_loop(unsigned long nb, char **str, int depth)
- {
- const char *hex = "0123456789abcdef";
- unsigned long index;
- index = nb % 16;
- if (nb / 16 > 0)
- ft_itohex_loop(nb / 16, str, (depth - 1));
- (*str)[depth] = hex[index];
- }
- char *ft_itohex(unsigned long nb, int depth)
- {
- char *str;
- int cpt;
- str = ft_strnew(depth + 1);
- cpt = 0;
- while (cpt <= depth)
- str[cpt++] = '0';
- ft_itohex_loop(nb, &str, depth);
- return (str);
- }
|