Binary, and Hex question.

jsbush

Diamond Member
Nov 13, 2000
3,871
0
76
How does FF (F=15) end up being 255? And how does 128 end up being a hex of 80?

How do you do the converstions from binary to hex?



Thanks.
 

emmpee

Golden Member
Nov 26, 2001
1,100
0
0
to convert from hex to decimal, multiply the rightmost digit by 16^0, the second right-most by 16^1, etc etc etc.

15 * 16^0 = 15
15 * 16^1 = 240
240 + 15 = 255

to go from binary to hex, take the binary digits in groups of 4 starting from the right. convert each group of 4 to a hex value. if you have less than 4 digits left, add leading zero's.

eg:

1110100101011

1011 = 11 (B)
0010 = 2
1101 = 13 (D)
0001 = 1

1110100101011 = 1D2B
 

mee987

Senior member
Jan 23, 2002
773
0
0
16 is your base. the far right place is 16^0 (ones). the left place is 16^1 (sixteens). so you have 15 sixteens (240) and 15 ones (15). that makes 255.
 

jsbush

Diamond Member
Nov 13, 2000
3,871
0
76
Oh ok I get it now.

8 = 1000

and

0 = 0000

so 80 equals 128 because 10000000 is 128

same with F
F = 1111
so FF = 11111111 and 11111111 is equal to 255



Thanks. :D
 

RossGr

Diamond Member
Jan 11, 2000
3,383
1
0
The conversion from binary to hex is very straight forward, no need to involve decimals. 1 hex digit is 4 binary digits.

Binary__Hex
0001 __ 1
0010__ 2
0011 __ 3
0100 __ 4
0101 __ 5
0110__ 6
0111 __7
1000 __ 8
1001__ 9
1010 __ A
1011 __ B
1100 __C
1101 __D
1110__ E
1111__ F


If you have 16 binary digits break it into 4 pieces and convert each to Hex
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
What everyone is talking about is not special to binary, hexadecimal, or any other number system; rather, it's simply the place-value system, a system that's independent of the base. You can thank the precocious Babylonians for said system.
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
178 in decimal = 1 * 100 + 7 * 10 + 8 * 1

Use similar logic in hex:

0xFF = 15 * 16 + 15 * 1

 

Cal166

Diamond Member
May 6, 2000
5,081
8
81
Took this class two semester's ago called Assemble Language. We had to write our own programs from scratch.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: Cal166
Took this class two semester's ago called Assemble Language. We had to write our own programs from scratch.

As opposed to....... instant programs? :D I believe you mean assembly (some call is assembler, but that's technically incorrect as well) language.