maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_print_unsigned_hex.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_print_unsigned_hex.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: rocky <rmikhayl@student.42london.com> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2024/01/07 15:47:43 by rocky #+# #+# */
9
/* Updated: 2024/01/07 15:47:43 by rocky ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "
libft.h
"
14
15
int
ft_hex_len
(
unsigned
int
n)
16
{
17
int
len;
18
19
len = 0;
20
while
(n != 0)
21
{
22
n = n / 16;
23
len++;
24
}
25
return
(len);
26
}
27
28
void
ft_put_hex
(
unsigned
int
n,
const
char
upper_lower)
29
{
30
if
(n >= 16)
31
{
32
ft_put_hex
(n / 16, upper_lower);
33
ft_put_hex
(n % 16, upper_lower);
34
}
35
else
36
{
37
if
(n <= 9)
38
ft_putchar_fd
((n +
'0'
), 1);
39
else
40
{
41
if
(upper_lower ==
'x'
)
42
ft_putchar_fd
((n - 10 +
'a'
), 1);
43
if
(upper_lower ==
'X'
)
44
ft_putchar_fd
((n - 10 +
'A'
), 1);
45
}
46
}
47
}
48
49
int
ft_print_unsigned_hex
(
unsigned
int
n,
const
char
upper_lower)
50
{
51
if
(n == 0)
52
{
53
ft_putchar_fd
(
'0'
, 1);
54
return
(1);
55
}
56
else
57
ft_put_hex
(n, upper_lower);
58
return
(
ft_hex_len
(n));
59
}
ft_print_unsigned_hex
int ft_print_unsigned_hex(unsigned int n, const char upper_lower)
Definition
ft_print_unsigned_hex.c:49
ft_hex_len
int ft_hex_len(unsigned int n)
Definition
ft_print_unsigned_hex.c:15
ft_put_hex
void ft_put_hex(unsigned int n, const char upper_lower)
Definition
ft_print_unsigned_hex.c:28
libft.h
ft_putchar_fd
void ft_putchar_fd(char c, int fd)
Definition
ft_putchar_fd.c:20
lib
libft
src
ft_print_unsigned_hex.c
Generated by
1.9.8