C program to convert char to hexadecimal


















Please clarify, what exactly to you want the second printf to print. Use snprintf to print to a buffer, then print that? Also remember the string terminating 0 byte. Looking at answers i dont think i was clear, sorry. So essentialy i have an array which is readingreg char but has hex values. I want its values to be string. Add a comment. Active Oldest Votes. David Ranieri David Ranieri This gives an error.

Probably it is a warning but I have Werror on. Are you sure? Same for godbolt: godbolt. Which compiler are you using? If I change the data type of temp to char , then I do not get any errors. I have gcc8. Thank you for the prompt update. The unsigned char data type is important only for the variable storing the byte-array, where using a char could cause an overflow.

Sign in Email. Forgot your password? Ask a Question. How do I convert a char to hex then store it to a variable? Please Sign up or sign in to vote. I know how to print hex to screen, but I dunno how to store it to variable. Copy Code. Posted Jun pm rudy-peto. Updated Jun pm CPallini.

Add a Solution. Richard MacCutchan Jun am. Why would you want to? The only time you need to convert it to hex is when you want to display it somewhare. So just store it in its native form, char, int, float etc.

Top Rated Most Recent. Accept Solution Reject Solution. Posted Jun pm Sergey Alexandrovich Kryukov. A bit helpful. I should not print kar[i], It should be looks like this. But anyway, I store each hex into buffer..

Last edited by Spidey; at AM. Originally Posted by sumanbangladesh. Originally Posted by Bjarne Stroustrup I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. It sounds like you're still thinking that hex values are somehow different than non-hex values.



0コメント

  • 1000 / 1000