+ 2

Can someone correct my code?

The objective of the code is to convert a hexadecimal string into a binary string. To do it so I've researched the process of conversion from one base to another that is write a hexadecimal number, isolate each character and return the binary equivalent in the form of a nibble, then put the nibbles all together. For example : 1A 1(0001) A(1010) 00011010 To implement this solution into a code I created a function that has a for loop to read the hexadecimal numbers, and two if statements to tell when a character is a number from 0 through 9 and when it is a character from A through F and then return the binary of each character. This is the code : https://code.sololearn.com/clB3DH3ay04b/#c The problem with the code is that when a hexadecimal number as the above 1A is received it doesn't show the correct binary sequence 00011010 it only shows this sequence of zeroes 0000000000 and it happens with any sequence. (It would be helpful if you write comments into the causes of the problem in the code before showing the solution).

23rd Sep 2019, 10:15 PM
Arley santos
Arley santos - avatar
2 Answers
0
No.
25th Sep 2019, 9:19 PM
Š”тŠ°Š½ŠøсŠ»Š°Š² Š”Š²ŠøŠ·ŠµŠ²
Š”тŠ°Š½ŠøсŠ»Š°Š² Š”Š²ŠøŠ·ŠµŠ² - avatar