Hello I’m trying to convert a decimal value to a hex using C in order to store it on my variable char data[] and use the data later for something else. Does any one know how I can do it? I’m new to C
Hello I’m trying to convert a decimal value to a hex using C in
Share
If you have a number stored in a “char” variable, it is stored in the machine in binary. When you print the variable, you can chose how to display the variable. For example, to display it in decimal, you may do:
To display it in hex, you may do:
You probably want to look at a book on C and check the printf formatting options, as you can do lots of things with how the value is displayed (as a character, octal, padding, etc.). Just keep in mind that the computer stores it in only one way. There is no conversion from one representation to another.