[C] declare a hexadecimal variable
____22
Posted messages
101
Status
Membre
-
stephbb75 Posted messages 620 Registration date Status Membre Last intervention -
stephbb75 Posted messages 620 Registration date Status Membre Last intervention -
Hello,
how to declare a hexadecimal variable in C
int x = 0x10;
what should I put instead of int? byte?
does x equal 10 or 16 in this case?
thanks for the help
how to declare a hexadecimal variable in C
int x = 0x10;
what should I put instead of int? byte?
does x equal 10 or 16 in this case?
thanks for the help
Configuration: Windows XP Internet Explorer 7.0
2 réponses
Hello,
Your variable will not have a specific base. In memory, the number is stored in binary.
It’s at display time that you can request the output in a certain base (16 for example).
When you do int x = 0x10; you are telling the compiler that the number you are entering is in base 16. It will store it in binary in memory. If you request a decimal display (printf("%d", x); you will get 16.
If you use printf("%x", x); it will be 10 (hex display).
--
Google is your friend
Your variable will not have a specific base. In memory, the number is stored in binary.
It’s at display time that you can request the output in a certain base (16 for example).
When you do int x = 0x10; you are telling the compiler that the number you are entering is in base 16. It will store it in binary in memory. If you request a decimal display (printf("%d", x); you will get 16.
If you use printf("%x", x); it will be 10 (hex display).
--
Google is your friend