views:

199

answers:

7

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.

Thanks

+10  A: 

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

GWW
+3  A: 

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

Robert
+3  A: 

1024 in decimal = 400 in hex.

funkymushroom
+3  A: 

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

Jonathan Grynspan
+6  A: 

0x400 is hexidecimal, 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.

John Dibling
+1  A: 

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

john
LOL “cast” :-D ...
Timwi
I mean, it makes the conversion... implicitly
john
+2  A: 

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
Casey