《16进制转10进制小程序.docx》由会员分享,可在线阅读,更多相关《16进制转10进制小程序.docx(2页珍藏版)》请在三一办公上搜索。
1、16进制转10进制小程序#include using namespace std; int Add(char *dec, int num, char hex) int Mult16(char *dec, int num) void HexToDec(char *hex, char *dec) int i, num, ndec; nCarry = 0; for(i = 0; i 0) return num; decnum+ = nCarry % 10 + 0; nCarry /= 10; nCarry += (deci - 0) * 16; deci = nCarry % 10 + 0; nCa
2、rry /= 10; int i, nCarry; for(i = 0; nCarry 0 & i 0) else return num; decnum = nCarry + 0; return num+1; nCarry += deci - 0; deci = nCarry % 10 + 0; nCarry /= 10; int i, nCarry; if(hex = a & hex = A & hex = F) nCarry = (hex & 0x0f) + 9; nCarry = hex & 0x0f; else char ch; num = strlen(hex); dec0 = 0;
3、 ndec = 1; for(i = 0; i num; i+) for(i = 0; i ndec/2; i+) decndec = 0; ch = deci; deci = decndec-1-i; decndec-1-i = ch; ndec = Mult16(dec, ndec); ndec = Add(dec, ndec, hexi); void main cout输入一个十六进制的串:; gets(hex); printf(十六进制串为:%sn, hex); HexToDec(hex, dec); printf(十进制数:%sn, dec); char dec200, hex100; int i(0), num(0), ndec(0);