-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_specifiers.c
100 lines (84 loc) · 1.62 KB
/
handle_specifiers.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
93
94
95
96
97
98
99
100
#include "main.h"
#include <unistd.h>
#include <stdio.h>
/**
* print_binary - integer in binary format
* @num: unsigned int to convert in binary format
*
* Return: number of caracter printed
*/
int print_binary(unsigned int num)
{
char buffer[32];
int i = 0, count;
if (num == 0)
{
write(1, "0", 1);
return (1);
}
while (num > 0)
{
buffer[i] = (num & 1) + '0';
num >>= 1;
i++;
}
count = i;
while (i > 0)
{
i--;
write(1, &buffer[i], 1);
}
return (count);
}
/**
* write_unsigned_int - Print unsigned number
* @num: number to write to output
* Return: Number of char sent
*/
int write_unsigned_int(unsigned int num)
{
char buffer[20];
int len;
len = snprintf(buffer, sizeof(buffer), "%u", num);
write(1, buffer, len);
return (len);
}
/**
* write_small_hexadecimal - print hexdecimal with small letter
* @num: number to output
* Return: Number of caracter
*/
int write_small_hexadecimal(unsigned int num)
{
char buffer[20];
int len;
len = snprintf(buffer, sizeof(buffer), "%x", num);
write(1, buffer, len);
return (len);
}
/**
* write_big_hexadecimal - print hexadecimal with cap letters
* @num: number to output
* Return: Number of character printed out
*/
int write_big_hexadecimal(unsigned int num)
{
char buffer[20];
int len;
len = snprintf(buffer, sizeof(buffer), "%X", num);
write(1, buffer, len);
return (len);
}
/**
* write_octal - print number in octal
* @num: Number to print
* Return: Number of character printed out
*/
int write_octal(unsigned int num)
{
char buffer[20];
int len;
len = snprintf(buffer, sizeof(buffer), "%o", num);
write(1, buffer, len);
return (len);
}