Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * hex2dec.cxx
- *
- * Copyright 2018 Денис <altracer@AspireE15>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- *
- */
- #include <iostream>
- #include <math.h>
- #include <locale.h>
- using namespace std;
- int main(int argc, char **argv)
- {
- setlocale(LC_ALL,"RUS");
- short l = 2;
- char a[l+1]; // last symbol is line terminator '\0'
- short b = 0;
- short i,j;
- cout << "Введите шестнадцатеричное число от 00h до FFh (без h):" << endl;
- cin >> a;
- const char hex_alphabet[17] = "0123456789ABCDEF";
- int dec_alphabet[16];
- for(i=0;i<=15;i++) dec_alphabet[i]=i;
- for(i=0;i<=l-1;i++){
- for(j=0;j<=15;j++){
- if(a[l-1-i]==hex_alphabet[j]) b+=dec_alphabet[j]*pow(16,i);
- };
- };
- cout << b <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement