-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_puthexa_upper.c
More file actions
48 lines (45 loc) · 1.49 KB
/
Copy pathft_puthexa_upper.c
File metadata and controls
48 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthexa_upper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nholbroo <nholbroo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 14:34:52 by nholbroo #+# #+# */
/* Updated: 2025/02/12 13:03:41 by nholbroo ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/*
Converts and prints a number in uppercase hexadecimal format to
the standard output.
Does not take integer overflow/underflow into consideration, so the number
should always be within unsigned int range.
Returns the amount of digits printed.
*/
int ft_puthexa_upper(unsigned int n)
{
char str[9];
int i;
int count;
i = 0;
count = 0;
if (n == 0)
return (write(1, "0", 1));
while (n > 0)
{
if (n % 16 < 10)
str[i] = n % 16 + '0';
else
str[i] = (n % 16) % 10 + 'A';
n /= 16;
i++;
}
str[i--] = '\0';
while (i >= 0)
{
write(1, &str[i--], 1);
count++;
}
return (count);
}