0

How can I separate an Hexadecimal?

Hello everyone, I'm new to this app and I hope you can help me with this code I did. I want to split the hex variable into 2 variables, example, the ASCII value for letter 'A' is 0x41. And I need to split this value like 0x04 (4 most significant bits) and 0x01 (4 least significant). #include <iostream> #include <string.h> using namespace std; int main() { char *str = "String example"; int cntr =strlen (str); char hex; for (int i=0; i<cntr; i++) { hex = str [i]; } }

2nd Nov 2017, 2:35 AM
Carlos Pérez
Carlos Pérez - avatar
3 ответов
+ 2
I hope I understood the question and this is all you asked for. https://code.sololearn.com/cvjGoMHorEyF/?ref=app This won't work for extended ASCII, because of the arithmetic shift, but ASCII values under 128 are ok. Edit: Ace noted that I could have used unsigned char and the above limitation would not be in effect, so I changed the code according to that.
2nd Nov 2017, 3:58 AM
OWRhcmFidQ==
+ 1
thanks bro!! it made my final code work!!
2nd Nov 2017, 5:18 AM
Carlos Pérez
Carlos Pérez - avatar
0
Out of words sorry, I want to split the hex value, since I'm using a PIC18F4550 to control a LCD, instead of sending hex values (as I was doing), just want to type a string and it would translate the ASCII value to actually display to the LCD the string, and want to simplify my code, but I'm using 4 bit mode, so I gotta send the most significant 4 bits first, then least 4 significant bits. Thank you for your help.
2nd Nov 2017, 2:43 AM
Carlos Pérez
Carlos Pérez - avatar