I've got a hex on me!

Because I can’t figure out how to convert from decimal/binary to hexadecimal or octal or any other radix for that matter. I can do decimal to binary and back pretty well but I that’s because I thought myself how to do that. My prof is pretty worthless trying to explain all this stuff. Can you guys give me any tips on how to do this stuff? And what’s biased -127/-128?

Here’s what I did: get a nice TI-34 solar powered calculator, they cost about $15 or so. They’ll convert decimal, binary, octal, and hex. :slight_smile:

Here’s a page that (about three-quarters of the way down) has links to pages that describe the nuts and bolts of a few non-decimal numbering systems:
url=“http://www.danbbs.dk/~erikoest/eoe_data.htm#top”]Erik Østergaard

Oops

Erik Østergaard
Sorry

That would be great but I still wouldn’t know what I was doing and how to do it. Plus I’m sure we couldn’t use them on a test.

The easiest way to understand number systems with bases other than ten might be to start with the base 10 system. We use a positional system in which the position of the number determines its value. Remember the old units, tens, hundreds, thousands, etc?
The number 2317 for example is really 2 times 1000 + 3 times 100 + 1 time 10 + 7 times 1. Or 2000 + 300 + 10 + 7.
The weight (what is multiplied by in each position) comes from the following , going left to right:

10 raised to the 3rd power (100), 10 raised to the 2nd power (100), 10 raised to the 1st power (10), 10 raised to the 0 power (1). From the law of exponents any number raised to the 0 power is 1.

To use a different base just plug it in instead of 10. For example for binary (base 2):

2 raised to the 3rd power (8), 2 raised to the 2nd power (4), 2 raised to the 1st power (2), 2 raised to the 0 power (1).

To convert a binary number such as 1011 to base 10 multiply each 1 by the proper weight and add them up.
1 times 8 + 0 times 4 + 1 times 2 + 1 times 1 = 8 + 0 + 2 +1 = 11.
Other number bases are treated in the same fashion.

Well, if you’re using Windows, it’s a little easier to convert hex/decimal/octal/binary.

Click on Start/Programs/Accessories/Calculator. Click on View/Scientific.

Enter the number in the base you want to go from, then click on the button for the base you want to go to, and it’ll convert it for you.

These are probably the quickest ways to convert by hand:

To convert from some base to base ten (building on what Diver said:

Say you want to convert 6253 base eight to base ten. Work from left to right, going digit by digit. At each step, first multiply by eight, then add the next digit. For example, starting with the first digit 6, multiply by eight:

48,

now add the next digit 2;

50,

now multiply by eight;

400,

now add the next digit 5;

405,

now multiply by eight;

3240,

now add the last digit 3;

3243 base ten, and we’re done. This works for converting any other base to base ten, simply change “multiply by eight” at each step to “multiply by whatever base you’re converting from”.

To go in reverse, say we want to convert 3243 base ten into base eight. At each step we’ll divide the previous quotient (for the first step we’ll start with the actual given number, 3243) by eight (or whatever base you’re converting into), saving the remainders which will make up the digits of the new number:

3243 divided by 8:

405, remainder 3.

405 divided by 8:

50, remainder 5.

50 divided by 8:

6, remainder 2.

6 divided by 8:

0, remainder 6.

Once the quotient hits zero we’re done, and write down the remainders in order, from right to left:

6253 base eight.

Cykrider, if you can do decimal to binary and back, you’re pretty much set-it’s incredibly easy to do conversions between octal and binary and hexadecimal and binary (which is why machine language programmers usually learn to think & calculate in octal or hex-it’s a lot easier than working directly in binary, but you can convert your numbers to binary if you need to in an eyeblink). Just memorize these handy-dandy conversion charts:

Octal Binary
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111

Hex Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111

To convert from octal or hex to binary, just replace each digit with the binary digits in the right column. To convert from binary to octal or hex, divide the binary number into groups of three or four digits (padding the left with zeroes if it the number of digits doesn’t divide out evenly) and replace each section with the octal or hex digit in the left column. Memorizing this table should be easier than memorizing the decimal addition & multiplication tables, and you did that in grade school! Once you’ve memorized it & practiced for a bit, you should be able to convert any binary number back & forth between octal and hexadecimal in a matter of seconds.

Thanks everyone for the information and links. However, I’m still not sure what this “biased 128” and stuff is. Something with finding a value and then subtracting 128 from it.

We’ve been working with 1’s compliment and 2’s compliment alot too if they’re some how related.

Thanks again for the help. This is really helping me to look in the right direction.

Might it have something to do with how you represent negative numbers?
Everybody nowadays use 2-compliment, as it makes for a very straight forwad way of adding negative numbers. For example, try to add -3 and 4:
Lets use four bits arithmetics,
-3 would then be 1101 (invert and add one)
4 is 0100
and if the two are added we get


   1101
  +0100
 ------
(1)0001

Discard the carry, and the result is one.
In this four bit code we can only represent the following numbers:


0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = -8
1001 = -7
1010 = -6
1011 = -5
1100 = -4
1101 = -3
1110 = -2
1111 = -1

You will notice that the symmetry is broken. There is more negative than positive. This might be what you have heard about. (I guess one could call this a -8 biased code).
One interesting thing to ponder is the normal binary code is by no means the only way to encode digits into bitfields. The reason it is chosen is that it is very easy to do arithmetics in it. For other purposes there are other, more obscure, codes. I recomend a search for Grey codes.

Ooops. That should have been Gray codes.
As in http://hissa.nist.gov/dads/HTML/graycode.html

A good analogy for biased representation is the comparison between temperature measurements by Celsius and Kelvin; they both operate on the same scale, but have different ‘zero points’.