-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_binary.c
More file actions
46 lines (43 loc) · 1.02 KB
/
print_binary.c
File metadata and controls
46 lines (43 loc) · 1.02 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
#include "_printf_internals.h"
/**
* print_binary - converts an unsigned int into binary.
* @args: the arguments to be formatted.
* @buffer: working buffer for `_printf`.
* @mods: modifier flags.
*
* Return: Returns a positive int on success, negative int on failure.
*/
int print_binary(va_list args, char_arr *buffer, modifiers mods)
{
uintmax_t num = 0;
switch (mods.length)
{
case PRINTF_CHAR:
num = (char)va_arg(args, int);
break;
case PRINTF_SHORT:
num = (short int)va_arg(args, int);
break;
case PRINTF_LONG:
num = va_arg(args, unsigned long int);
break;
/* case PRINTF_LLONG: */
/* num = va_arg(args, unsigned long long int); */
/* break; */
case PRINTF_INTMAX_T:
num = va_arg(args, uintmax_t);
break;
case PRINTF_SIZE_T:
num = va_arg(args, size_t);
break;
case PRINTF_PTRDIFF_T:
num = va_arg(args, ptrdiff_t);
break;
default:
num = va_arg(args, unsigned int);
break;
}
mods.int_mod.base = BASE02;
mods.int_mod.is_negative = false;
return (format_integers(num, buffer, mods));
}