Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C programing help for convertion of ASCII to Hex..

Status
Not open for further replies.

swatip

Newbie level 6
Newbie level 6
Joined
May 11, 2011
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,356
Hiii..

How to write a C program for converting ASCII char into HEX numbers???
E.g. for char-'A' output is Hex-0x41 likewise..
Any one knows???
 

Try this :

**broken link removed**


or try this :



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char hexDigit(unsigned n)
{
    if (n < 10) {
        return n + '0';
    } else {
        return (n - 10) + 'A';
    }
}
 
void charToHex(char c, char hex[3])
{
    hex[0] = hexDigit(c / 0x10);
    hex[1] = hexDigit(c % 0x10);
    hex[2] = '\0';
}


https://stackoverflow.com/questions/3212848/how-to-convert-from-ascii-to-hex-and-vice-versa
 
Last edited by a moderator:

Hi,
Try This code . I hope it will help you.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
char mychar='R';
 
char HEX1=mychar/16;
if (HEX1<=9) HEX1+='0';
else HEX1=HEX1-10+'A';
 
char HEX2=mychar%16;
if (HEX2<=9) HEX2+='0';
else HEX2=HEX2-10+'A'
 
cout << " Hex equivalent : " << HEX1 << HEX2;;

 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top