English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In c++, I see the value '0x1401' used as a constant. What value does this represent?

2006-11-03 13:20:23 · 6 answers · asked by johnkonradgrant 1 in Computers & Internet Programming & Design

6 answers

decimal uses numbers 0,1,2,3,4,5,6,7,8,9
Binary uses 0,1
Hex uses 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f ( for 0 through 15)

Decimal you know
Binary is simple , we'll use 8 numeric values
00000000 (binary)
87654321 ( placement)
from right to left
placement = value
1 = 1
2 = 2
3 = 4
4 = 8
5 = 16
6 = 32
7 = 64
8 = 128

or 2^ placement

so 00000001 = decimal 1
so 00001000 = decimal 8
so 00001001 = decimal 9 ( 8 + 1)
so 01000000 = decimal 64
so 01001001 = decimal 73 ( 64 + 8 + 1 )

Now hex is different, it uses groups of 4 binary numbers
00000000 = 00 hex = 0 dec
00000001 = 01 hex = 1 dec
00001001 = 09 hex = 9 dec
00001100 = 0c hex = 12 dec
01001100 =4c hex = 76 dec

hex 1401 = 0001 0100 0000 0001 binary
dec = 1 + 1024 + 4096

2006-11-03 13:35:34 · answer #1 · answered by Juggernaut 3 · 1 0

decimal systems are base 10 systems, while binary systems are base2 systems. hexadecimal systems are base16 systems.
e.g. given a decimal number 1453, we know that its true value us 1 * 10 ^3 + 4 * 10 ^2 + 5 * 10 ^1 + 3 * 10 ^ 0. This is base 10 system because you will multiply the number by power of 10, to get its value. Similarly base 2 means you will multiply the number by the powers of twos. As its a base two system, you can only use 2 digits, i.e. 0 and 1. So a number 1001, actually represents the value 1 * 2 ^3 + 1* 2 ^0 = 9. SImilarly with hexadecimal systems. in hexadecimal you can used 16 numbers to represents one place. these are 0 to 9 and then A to F. A represents 10 and F represents 15. So a number in hexadecimal 0x1401, actually got value 1 * 16 ^ 3 + 4 * 16 ^2 + 0 * 16 ^ 1 + 1.
To convert decimal number to binary, you must constantly divide that number by 2, and place the reminder. Continue this untill you get zero. Similary to get a hexadecimal number you should continue dividing it by 16 and place the reminder.

2006-11-03 17:54:15 · answer #2 · answered by manoj Ransing 3 · 0 0

Remember in math class when they were giving you instructions of polynomials.

binary 101 = 1*2^2 + 0*2^1 + 1*2^0 = 5

43 = 4*10^1 + 3*10^0

hex is trickey because you have to know the values of a b c d e and f

a = 10 b = 11 c = 12 ... f = 15

0xef = 14*16^1 + 15*16^0 = 239

Your problem would be
1*16^3 + 4*16^2 + 0*16^1 + 1== 5121
4096 + 1024 + 1
We use calculators to figure this stuff out. The windows calculator in scientific mode can convert for you.

2006-11-03 13:41:33 · answer #3 · answered by To Be Free 4 · 0 0

Values with a '0x' prefix are in hexadecimal. These are just numbers, but they use 16 as a base instead of 10. This means their digits go from 0 to F (counting as 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) instead of 0..9.

hexadeicmal values can be easily converted after some time becoming familiar with them. The fastest way to get yous started is just to open the windows calculator (in scientific mode) and choose 'Hex' as the base. Enter what you see (without the 0x prefix) and then click on 'Dec' to have it converted.

2006-11-03 13:34:51 · answer #4 · answered by WickedSmaht 3 · 0 0

O-K, so do you want a lesson in basic high-school math
(Mr. C++)?
(e-mail me) (I'm really a nice guy)

Or do you just want a calculator?

Sorry to seem like such a jackass.

I guess I just blew my chance at being voted as "Best Answer".

Here 'ya go...

http://www.cut-the-knot.org/binary.shtml

http://www.easycalculation.com/hex-converter.php

2006-11-03 13:52:40 · answer #5 · answered by troydowning 5 · 0 0

i can do it mathmatically.
it easy. if you want to know i can show you

2006-11-03 13:24:30 · answer #6 · answered by bangla answer 3 · 0 0

fedest.com, questions and answers