• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2. #include <stdlib.h>
3. #include <math.h>
4.
5. int any_to_any(int ns1, int v1, int ns2)
6. {
7.     int new_value=0;
8.     //Still working on integral numbers, conversion available on systems from bin to decimal.
9.     //First changing current numeric system value into decimal.
10.     new_value = any_to_dec(ns1, v1);
11.     //Checking if target numeric system is decimal. If true we already got it converted.
12.     if(ns2 == 10)
13.         return new_value;
14.     return 0;
15. }
16.
17. int any_to_dec(int ns, int v)
18. {
19.     //Changing from any to decimal for later conversion.
20.     int new_value = 0;
21.     int value_d = 0;
22.     int value_e = 0;
23.     double value_taker = 0, value_dd = 0;
24.     int E=0;
25.     //Finding how much number this value have.
26.     while(pow(10,E)<v)
27.     {
28.         E++;
29.     }
30.     //Separating first number of value (the highest).
31.     // zB. 2432 -> 4 number -> 2432/pow(10,4-1) = 2.432 -> int = 2 (first number).
32.     for(int i=0; i<E; i++)
33.     {
34.         value_taker = (v/pow(10, E-1-i));
35.         value_d = value_taker;
36.         value_dd = value_d;
37.         value_e = value_taker - (value_dd * pow(10, i));
38.         new_value = new_value + (value_e * pow(ns, E-1-i));
39.     }
40.     return new_value;
41. }
42.
43. int main()
44. {
45.     //Working on int for now, it will work on numeric system from binary to decimal.
46.     //Need to change v1 into char tab because of letter in greater than decimal systems. [To do later]
47.     int ns1=0, ns2=0, v1=0, v2=0;
48.     printf("Welcome to any_to_any numeric conversion system!\n");
49.
50.     printf("Enter current numeric system: ");
51.     //scanf("%d", &ns1);
52.     ns1=4;
53.     printf("Enter current value: ");
54.     //scanf("%d", &v1);
55.     v1=2312;
56.     printf("Enter traget numeric system: ");
57.     //scanf("%d", &ns2);
58.     ns2=10;
59.     v2 = any_to_any(ns1, v1, ns2);
60.     printf("New value from %d of %d numeric system is value %d of %d numeric system", v1, ns1, v2, ns2);
61.     return 0;
62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top