IM A NOOB I NEED HELP WITH MY CODE PLS ANYONE HELP ME YOUR HELP WOULD MEAN A LOT :""((( | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

IM A NOOB I NEED HELP WITH MY CODE PLS ANYONE HELP ME YOUR HELP WOULD MEAN A LOT :""(((

so i tried making a program that converts hexadecimal number into decimal number and here is my progress so far https://code.sololearn.com/c3I2be4hYaTw/#cpp can anyone correct me whats wrong with this code and what should i do next

21st Nov 2018, 11:04 AM
Annida Miftakhul Farodisa
Annida Miftakhul Farodisa - avatar
1 Answer
0
You have made just a mapping between one hex number to decimal. You have to make calculations when more than one hex characters are used. For example : If the hexadecimal number is 1A. dec_value = 1*(16^1) + 10*(16^0) = 26 Step 1 : Read char array not single char Step 2: Create a function converting hex number to dec passign as parameter the char array and return an integer Inside the function 2a. Find the char array length and initialise dec_val = 0; 2b. Set base variable to 1 (16^0) 2c. Loop array (for (int i=len-1; i>=0; i--)) 2c1. if the character is between [0-9] then dec_val += (hexVal[i] - 48)*base; else if the character is between [A-F] then dec_val += (hexVal[i] - 55)*base; 2C2. increase base base = base*16; close loop
21st Nov 2018, 11:41 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar