Im working in C++ and I have a #define VAL 0x00000400. when I set a variable equal to the define: int value = VAL; when I run through the debugger is shows the variable value = 1024. could someone explain how that turns into 1024? Maybe some links to memory address info, #define info, or something relevant.

9

7 Answers

0x00000400 is base 16 for 1024. Your debugger is showing you the integer value in base 10.

"0x400" is hexadecimal, or base 16. 0x400 expressed as decimal (base 10), is 1024.

By the way, you can use google to do base conversions. Search for "0x400 in decimal" and google will give you the answer.

1

0x00000400 is 400 base 16, which is 1024 base 10.

1024 in decimal = 400 in hex.

0x400 is a hexadecimal number (indicated by the 0x prefix.) It is another way of representing the decimal number 1024.

Additionally, the conversion from 0x400 (base 16) to base 10 is:

4*16^2 + 0*16^1 + 0*16^0 4*16^2 + 0 + 0 4*256 1024 

well, I haven't seen your code, but 400h = 1024 decimal and you specify integer ' int value = VAL ' compiler just does not display any notice/warning, it does the cast for you

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.