-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhex to bin.cpp
More file actions
71 lines (64 loc) · 1.41 KB
/
Copy pathhex to bin.cpp
File metadata and controls
71 lines (64 loc) · 1.41 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
int hex(char []);
int main()
{
char hexa[100];
long int i = 0;
printf("Enter the value for hexadecimal ");
scanf("%s", hexa);
hex(hexa);
return 0;
}
int hex(char hexa[])
{
int i=0;
printf("\n Equivalent binary value: ");
while (hexa[i])
{
switch (hexa[i])
{
case '0':
printf("0000"); break;
case '1':
printf("0001"); break;
case '2':
printf("0010"); break;
case '3':
printf("0011"); break;
case '4':
printf("0100"); break;
case '5':
printf("0101"); break;
case '6':
printf("0110"); break;
case '7':
printf("0111"); break;
case '8':
printf("1000"); break;
case '9':
printf("1001"); break;
case 'A':
case 'a':
printf("1010"); break;
case 'B':
case 'b':
printf("1011"); break;
case 'C':
case 'c':
printf("1100"); break;
case 'D':
case 'd':
printf("1101"); break;
case 'E':
case 'e':
printf("1110"); break;
case 'F':
case 'f':
printf("1111"); break;
default:
printf("\n Invalid hexa digit %c ", hexa[i]);
return 0;
}
i++;
}
}