-
Notifications
You must be signed in to change notification settings - Fork 0
/
numsysco.bak
319 lines (286 loc) · 8.05 KB
/
numsysco.bak
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// #include<iostream.h>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
char s[100],c[1],x;
int l=0,p,u=0,j,base,t=1,bvd,chd;
float x1,y1,s0=0,z,z1,s2=0,s3=0,w;
float zs,w6,as,bs,a1s,b1s,ash,bsh;
int ys,z6s,ts,ss[100],is=1,ps,vs,w1s,cs,w2s,c1s,csh,vsh,w2sh,n;
float it2doc ()
{
while(s[l]!='\0')
{
if(s[l]!='.')
{l++;}
if(s[l]== '.')
break;
}
p=l;
for(j=p-1; j>=0; j--)
{
c[0]=s[j];
x1 = c[0] ;
if ((x1==65)||(x1 ==97))
{ x1= 10; }
else if ((x1== 66)||(x1==98))
{ x1= 11; }
else if ((x1== 67)||(x1==99))
{ x1= 12; }
else if ((x1== 68)||(x1==100))
{ x1= 13; }
else if ((x1== 69)||(x1==101))
{ x1= 14; }
else if ((x1== 70)||(x1==102))
{ x1= 15; }
else
{ x1 = x1-48; } //atof(c); }
y1= x1* pow(base,u);
u++;
s0=s0+y1;
}
l++;
while(s[l]!='\0')
{
c[0]= s[l];
z = c[0];
if ((z==65)||(z ==97))
{ z= 10; }
else if ((z== 66)||(z==98))
{ z= 11; }
else if ((z== 67)||(z==99))
{ z= 12; }
else if ((z== 68)||(z==100))
{ z= 13; }
else if ((z== 69)||(z==101))
{ z= 14; }
else if ((z== 70)||(z==102))
{ z= 15; }
else
{ z = z-48; } //atof(c); }
// z = atof(c);
z1= z*1/(pow(base,t));
s2=s2+z1;
t++;
l++;
}
s3=s0+s2;
return s3;
}
int dotbin()
{
b1s=a1s*2;
c1s=b1s;
a1s=b1s-c1s;
return c1s;
}
int dotoct ()
{
bs=as*8;
cs=bs;
as=bs-cs;
return cs;
}
int dothex ()
{
bsh=ash*16;
csh=bsh;
ash=bsh-csh;
return csh;
}
int checkit ()
{ n=0;
while(s[n]!= '\0')
{ if(s[n]=='.')
{ n++;
goto next;}
else { if(base==16)
{ if ((s[n]== 'A')||(s[n]== 'B')||(s[n]== 'C')||(s[n]== 'D')||(s[n]== 'E')||(s[n]== 'F')||(s[n]== 'a')||(s[n]== 'b')||(s[n]== 'c')||(s[n]== 'd')||
(s[n]== 'e')||(s[n]== 'f')||(s[n]== '1')||(s[n]== '2')||(s[n]== '3')||(s[n]== '4')||(s[n]== '5')||(s[n]== '6')||(s[n]== '7')||(s[n]== '8')||(s[n]== '9')||(s[n]== '0'))
{chd=0;}
else { chd=1;}
}
if(base==10)
{ if ((s[n]=='1')||(s[n]== '2')||(s[n]== '3')||(s[n]== '4')||(s[n]== '5')||(s[n]== '6')||(s[n]== '7')||(s[n]== '8')||(s[n]== '9')||(s[n]== '0'))
{chd=0;}
else { chd=1;}
}
if(base==8)
{ if ((s[n]== '1')||(s[n]== '2')||(s[n]== '3')||(s[n]== '4')||(s[n]== '5')||(s[n]== '6')||(s[n]== '7')||(s[n]== '0'))
{chd=0;}
else { chd=1;}
}
if(base==2)
{ if ((s[n]== '0') || (s[n]== '1'))
{chd=0;}
else { chd=1;}
}
n++;
}
if( chd!= 0)
{ goto term; }
}
next: while(s[n]!= '\0')
{ if(s[n]=='.')
{ chd=1;
n++;}
else { if(base==16)
{ if ((s[n]== 'A')||(s[n]== 'B')||(s[n]== 'C')||(s[n]== 'D')||(s[n]== 'E')||(s[n]== 'F')||(s[n]== 'a')||(s[n]== 'b')||(s[n]== 'c')||(s[n]== 'd')||
(s[n]== 'e')||(s[n]== 'f')||(s[n]== '1')||(s[n]== '2')||(s[n]== '3')||(s[n]== '4')||(s[n]== '5')||(s[n]== '6')||(s[n]== '7')||(s[n]== '8')||(s[n]== '9')||(s[n]== '0'))
{chd=0;}
else { chd=1;}
}
if(base==10)
{ if ((s[n]=='1')||(s[n]== '2')||(s[n]== '3')||(s[n]== '4')||(s[n]== '5')||(s[n]== '6')||(s[n]== '7')||(s[n]== '8')||(s[n]== '9')||(s[n]== '0'))
{chd=0;}
else { chd=1;}
}
if(base==8)
{ if ((s[n]== '1')||(s[n]== '2')||(s[n]== '3')||(s[n]== '4')||(s[n]== '5')||(s[n]== '6')||(s[n]== '7')||(s[n]== '0'))
{chd=0;}
else { chd=1;}
}
if(base==2)
{ if ((s[n]== '0') || (s[n]== '1'))
{chd=0;}
else { chd=1;}
}
n++;
}
if( chd!= 0)
{ goto term; }
}
term: return chd;
}
void main()
{ printf(" Welcome to Number System Converter \n Convert any number( not GREATER than 32750) to other number systems \n(conventional) \n EVEN with DOTTED number.(such as: 123.456 or ABC.DEF) \n \n");
printf("WARNING: ");
printf("You might see WRONG convertion in if you INPUT a number \n GREATER than 32767.00 in DECIMAL value \n ");
printf("OTHERWISE Everything's OKAY. You can Totally TRUST ME :) \n \n");
printf(" B = Binary \n D = Decimal \n H = Hexadecimal \n O = Octal \n");
again : printf("In which number system you want to input? ");
scanf("%c",&x);
if ((x=='B')||(x=='b'))
{
printf("In Binary, There should be NO Negative integer (Only 0 & 1),NO Symbols or \n Letters.\n \n");
again2: printf("Enter a number in BINARY (not GREATER than 111111111111111.00 (15s 1) ");
printf("\n");
scanf("%s",&s);
base = 2;
bvd =checkit();
if(bvd!=0)
{ printf("Enter a CORRECT Binary number,please.");
printf("\n");
printf("In Binary, There should be NO Negative integer (Only 0 & 1),NO Symbols or \n Letters. \n \n");
goto again2;}
else { w= it2doc();}
}
else if ((x=='O')||(x=='o'))
{
printf("In Octal, There should be NO Negative integer (Only 0 to 7),NO Symbols or \n Letters. \n \n");
again3:
printf("Enter a number in OCTAL (not GREATER than 77777.00 (5s 7)");
scanf("%s",&s);
base = 8;
bvd =checkit();
if(bvd!=0)
{
printf("Enter a CORRECT Octal number,please.");
printf("\n");
printf("In Octal, There should be NO Negative integer (Only 0 to 7),NO Symbols or \n Letters. \n \n");
goto again3;}
else {w= it2doc();}
}
else if((x=='D')||(x=='d'))
{ printf("In Decimal, There should be NO Negative integer (Only 0 to 9),NO Symbols or \n Letters. \n \n");
again4:
printf("Enter a number in DECIMAL (number GREATER than 35767 will have an MISTAKEN convertion in BINARY.\n number GREATER than 65535 will have MISTAKEN convertion in other systems.\n Now please Enter ");
scanf("%s",&s);
base = 10;
bvd =checkit();
if(bvd!=0)
{
printf("Enter a CORRECT Decimal number,please.");
printf("\n");
printf("In Decimal, There should be NO Negative integer (Only 0 to 9),NO Symbols or \n Letters. \n \n");
goto again4;}
else {w= atof(s);}
}
else if ((x=='H')||(x=='h'))
{ printf("In Hexadecimal, There should be NO Negative integer (Only 0 to 9 and \n A= 10, B= 11, C= 12, D= 13, E= 14,F= 15 ),NO Other Symbols or \n Letters. \n \n");
again5:
printf("Enter a number in HEXADECIMAL (not GREATER than 7FFFF.00)");
scanf("%s",&s);
base = 16;
bvd =checkit();
if(bvd!=0)
{
printf("Enter a CORRECT Hexadecimal number,please.");
printf("\n");
printf("In Hexadecimal, There should be NO Negative integer (Only 0 to 9 and \n A= 10, B= 11, C= 12, D= 13, E= 14,F= 15 ),NO Other Symbols or \n Letters. \n \n");
goto again5;}
else {w= it2doc();}
}
else {
printf("Enter a correct syntax \n");
printf(" B = Binary \n D = Decimal \n H = Hexadecimal \n O = Octal \n");
goto again;
}
printf("\n");
if(base!=10)
{ printf("\n");
printf(" Decimal is %.6f (Approximate value) \n",w);
}
zs=w;
ys=zs;
z6s=ys;
w= zs-ys;
as=w;
a1s=w;
ash=w;
if( base!=2)
{
printf(" Binary is ");
while(z6s!=0) {
ts=z6s%2;
z6s=z6s/2;
ss[is]=ts;
is++;
}
// while(z1!=0);
for(ps=is-1;ps>=1;ps--)
{ printf("%d",ss[ps]);
}
printf(".");
for (vs=1;vs<=6;vs++)
{
w1s=dotbin();
printf("%d",w1s);
}
printf(" (Approximate value)");
}
printf("\n");
if(base!=8)
{
printf(" Octal is %o",ys);
printf(".");
for (vs=1;vs<=6;vs++)
{ w2s= dotoct();
printf("%o",w2s);
}
printf(" (Approximate value)");
printf("\n");
}
if(base!=16)
{
printf(" Hexadecimal is %X.",ys);
for (vsh=1;vsh<=6;vsh++)
{ w2sh= dothex();
printf("%X",w2sh);
}
printf(" (Approximate value) \n \n");
}
printf("\n Thanks for trying me.\n");
printf(" You think it's awesome??? Okay,Then share to your friends. \n");
printf(" © Copyright NumSySCo by MD.Gazzali Fahim \n");
}