-
Notifications
You must be signed in to change notification settings - Fork 1
/
formats_advanced_num.c
executable file
·92 lines (75 loc) · 1.91 KB
/
formats_advanced_num.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "holberton.h"
/**
* f_bin - The "%b" custom format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%b" string.
*/
char *f_bin(va_list arg_l, unsigned int precision)
{
char *binary;
precision = precision;
binary = _uitoa_b_o_h(va_arg(arg_l, unsigned int), 2, 0);
return (binary);
}
/**
* f_uint - The "%u" format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%u" or "%hu" string.
*/
char *f_uint(va_list arg_l, unsigned int precision)
{
char *u_integer;
u_integer = _uitoa_b_o_h(va_arg(arg_l, unsigned int), 10, 0);
if (precision != UINT_MAX)
u_integer = prec_uint(u_integer, precision);
return (u_integer);
}
/**
* f_oct - The "%o" format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%o" or "%ho" string.
*/
char *f_oct(va_list arg_l, unsigned int precision)
{
char *octal;
octal = _uitoa_b_o_h(va_arg(arg_l, unsigned int), 8, 0);
if (precision != UINT_MAX)
octal = prec_uint(octal, precision);
return (octal);
}
/**
* f_hexl - The "%x" format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%x" or "%hx" string.
*/
char *f_hexl(va_list arg_l, unsigned int precision)
{
char *hex;
hex = _uitoa_b_o_h(va_arg(arg_l, unsigned int), 16, 0);
if (precision != UINT_MAX)
hex = prec_uint(hex, precision);
return (hex);
}
/**
* f_hexu - The "%X" format specifier.
* @arg_l: The argument list to be operated.
* @precision: The precision amount.
*
* Return: The formatted "%X" or "%hX" string.
*/
char *f_hexu(va_list arg_l, unsigned int precision)
{
char *hex;
hex = _uitoa_b_o_h(va_arg(arg_l, unsigned int), 16, 1);
if (precision != UINT_MAX)
hex = prec_uint(hex, precision);
return (hex);
}