How to increase / decrease hexadecimal value in C

I am trying to create a counter using hex, I know that this can be easily done using decimal places, but is it possible to do this in hexadecimal format, or is it the same in dec?

will it be so

myhex = 0x00; myhex++; 

or will it be done in a completely different way?

If you ask why hex is because it is for the MCU, and for me the best way to control the IO MCU is to use hex.

+7
c increment hex
source share
1 answer

Yes, if you try this, you will see that it does not matter if number hex , octal or decimal !

As an example:

 #include <stdio.h> int main() { int myhex = 0x07; int myOct = 07; int myDec = 7; printf("Before increment:\n"); printf("Hex: %x\n", myhex); printf("Oct: %o\n", myOct); printf("Dec: %d\n", myDec); myhex++; myOct++; myDec++; printf("After increment:\n"); printf("Hex: %x\n", myhex); printf("Oct: %o\n", myOct); printf("Dec: %d\n", myDec); return 0; } 

Output:

 Before increment: Hex: 7 Oct: 7 Dec: 7 After increment: Hex: 8 Oct: 10 Dec: 8 
+7
source share

All Articles