| | |
convert char to hexadecimal
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 29
Reputation:
Solved Threads: 0
i want to convert char array element into hexadecimal value. But the code i wrote is not giving the output as i expect.
this is not working as i wanted.
i want..
unsigned char in[] = {0x0044,ox0055,.....};
can anyone help me to correct this...
C++ Syntax (Toggle Plain Text)
unsigned char in[256]; void Text(const char *Buffer) { static char tempValue[256]; for(int i=0;i<=len;i++) { sprintf(&tempValue[i],"%02x", (unsigned char)Buffer[i]); in[i]=(unsigned char)tempValue[i]; cout<<"HexaValue"<<in[i]; } }
this is not working as i wanted.
i want..
unsigned char in[] = {0x0044,ox0055,.....};
can anyone help me to correct this...
Last edited by Ancient Dragon; Apr 20th, 2008 at 11:49 am. Reason: add code tags
you can try something like this: But your tempValue buffer may not be large enough, depending on the length of the string. Should be at least string length * 7, maybe larger.
C++ Syntax (Toggle Plain Text)
char temp[16]; tempValue[0] = 0; // put below in a loop for each character sprintf(temp,"0x%04X, ", Buffer[i]); strcat(tempValue, temp);
Last edited by Ancient Dragon; Apr 20th, 2008 at 11:56 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Hexadecimal and Linear feed shift register :( (C)
- how to use hexadecimal value to obtain the character value in c# (C#)
- Convert string to to HEX (C)
- Stuck a bit on input (C)
- pls help me to convert char to integer. (C)
- Converting Hexadecimal characters to integers. (C++)
Other Threads in the C++ Forum
- Previous Thread: FILE and iostream
- Next Thread: C++ Assignment NEED HELP URGENTLY
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






