Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int any_to_any(int ns1, int v1, int ns2)
- {
- int new_value=0;
- //Still working on integral numbers, conversion available on systems from bin to decimal.
- //First changing current numeric system value into decimal.
- new_value = any_to_dec(ns1, v1);
- //Checking if target numeric system is decimal. If true we already got it converted.
- if(ns2 == 10)
- return new_value;
- return 0;
- }
- int any_to_dec(int ns, int v)
- {
- //Changing from any to decimal for later conversion.
- int new_value = 0;
- int value_d = 0;
- int value_e = 0;
- double value_taker = 0, value_dd = 0;
- int E=0;
- //Finding how much number this value have.
- while(pow(10,E)<v)
- {
- E++;
- }
- //Separating first number of value (the highest).
- // zB. 2432 -> 4 number -> 2432/pow(10,4-1) = 2.432 -> int = 2 (first number).
- for(int i=0; i<E; i++)
- {
- value_taker = (v/pow(10, E-1-i));
- value_d = value_taker;
- value_dd = value_d;
- value_e = value_taker - (value_dd * pow(10, i));
- new_value = new_value + (value_e * pow(ns, E-1-i));
- }
- return new_value;
- }
- int main()
- {
- //Working on int for now, it will work on numeric system from binary to decimal.
- //Need to change v1 into char tab because of letter in greater than decimal systems. [To do later]
- int ns1=0, ns2=0, v1=0, v2=0;
- printf("Welcome to any_to_any numeric conversion system!\n");
- printf("Enter current numeric system: ");
- //scanf("%d", &ns1);
- ns1=4;
- printf("Enter current value: ");
- //scanf("%d", &v1);
- v1=2312;
- printf("Enter traget numeric system: ");
- //scanf("%d", &ns2);
- ns2=10;
- v2 = any_to_any(ns1, v1, ns2);
- printf("New value from %d of %d numeric system is value %d of %d numeric system", v1, ns1, v2, ns2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement