[Solved] Ideas for adding the hex column | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

[Solved] Ideas for adding the hex column

https://www.sololearn.com/compiler-playground/c3klH7Gdvzp8?ref=app I want to add another column which will be the hex value.. Should I enum the 0 - F or something like a switch statement.. Any ideas??

13th Oct 2023, 9:45 PM
William Owens
William Owens - avatar
2 Answers
+ 4
Do another column but this time for the hexadecimal value. For the hexadecimal you can do the printf with the format %x. You don't even need to make the convertion.
13th Oct 2023, 10:51 PM
Werg Serium
Werg Serium - avatar
+ 3
William Owens I support Werg Serium's answer as the best solution. Upon examining the code, I noticed a bug. It writes outside the bounds of the bin[] array with this line: bin[8] = '\0'; It is easily corrected, though, by adding one more element in the declaration (bin[9]) so it makes space for the terminating null. Indeed, after that you can delete the above line altogether, because the code never overwrites the null after initialization. Here is my first draft at a revision. There is some code reduction in the binary conversion. https://code.sololearn.com/cwNYQ43vDMHw/?ref=app
14th Oct 2023, 12:37 AM
Brian
Brian - avatar