Sometimes one need to convert from a ASCII to hex of a particular character. Here is a small function that will take care of that need. It will convert only 0 .. 9 , a .. f , A .. F , rest of the character will be returned as it is.
char atoh(char ch){
if(ch >= 0x30 && ch <= 0x39){
return (ch - 0x30);
}else if(ch >= 0x41 && ch <= 0x46){
return (ch - 0x37);
}else if(ch >= 0x61 && ch <= 0x66){
return (ch - 0x57);
}else{
return ch;
}
}
No comments:
Post a Comment