I'm trying to create a counter using hex, I know this can easily be done using decimals, but is it possible to do this in hex, or is it the same in dec?
will it go like this?
myhex = 0x00;
myhex++;
or will it be done on an entirely different manner?
If you are asking why hex its because this is for an MCU and for me the best way to control the IO of MCU is using hex.
Yes if you try it you will see it, that it makes no difference if the number
is 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With