Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to convert an ascii to hex

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
HI
im a newbie
i want a source code that converts the ascii into hex.
Thanx
 
here are the basics

Code:
char buffer[128];
// read in buffer
// now buffer contains some string

int len = strlen(buffer);
char hex[4];
memset(hex,0,4);
   
for(int i = 0;i<len;i++)
{
   sprintf(hex,&quot;%x&quot;,buffer[i]);
   // hex now contains the string equiv of the hex value
}

//if you just want to output in hex

cout<<hex<<buffer[i]<<endl;
could replace the sprintf

In actuallity, the decimal value is hex which is binary which is octal. You just need to know the conversions for the different representations.

Matt

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top