Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cmath>
- using namespace std;
- int main()
- {
- setlocale(0,"rus");
- char st[10];
- int i,k,p,s=0,w;
- cout<<"Введите число в 16-ричной системе счисления: \n";
- cin>>st;
- p=strlen(st)-1;
- for (i=0; st[i]!='\0'; i++)
- {
- switch (st[i])
- {
- case 'A': k=10; break;
- case 'B': k=11; break;
- case 'C': k=12; break;
- case 'D': k=13; break;
- case 'E': k=14; break;
- case 'F': k=15; break;
- case '1': k=1; break;
- case '2': k=2; break;
- case '3': k=3; break;
- case '4': k=4; break;
- case '5': k=5; break;
- case '6': k=6; break;
- case '7': k=7; break;
- case '8': k=8; break;
- case '9': k=9; break;
- case '0': k=0; break;
- }
- s+=k*pow(16,p);
- p--;
- }
- cout<<"Результат: ";
- cout<<s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement