------------------

I wish there was a button on my monitor to turn up the intellegince.

Theres a button called 'brightness' but it doesn't work

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."

Sheriff

1 = 0001

-1 = 1110+1 = 1111

SCJP

Visit my download page

------------------

I wish there was a button on my monitor to turn up the intellegince.

Theres a button called 'brightness' but it doesn't work

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."

In this case, the binary value of 14 would be:1110.

You can apply this process to any number, to get its binary equivalent.

But, as Grant has suggested, calculators are always a good bet.

------------------

I wish there was a button on my monitor to turn up the intellegince.

Theres a button called 'brightness' but it doesn't work

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."

86/2=43

43/2=21 r1

21/2=10.5 ??

10.5/2=5.25 ??

5.25/2=2.625 ??

2.625/2=1.3125 ??

would the answer be 011111? I doubt it there must have been some rules left out or a misunderstanding.

------------------

I wish there was a button on my monitor to turn up the intellegince.

Theres a button called 'brightness' but it doesn't work

[This message has been edited by Brett Knapik (edited February 06, 2001).]

128 64 32 16 8 4 2 1

Then I take my number, and find the biggest one that would fit, in the example, it was 86, so ti put a 1 under 64:

128 64 32 16 8 4 2 1

0 1

Then subtract 64 from 86, leaving 22, take 22, and put a 1 under 16:

128 64 32 16 8 4 2 1

0 1 0 1

Leaving 6, repeat the process, and you get:

128 64 32 16 8 4 2 1

0 1 0 1 0 1 1 0

And that's the binary for 86.

You can double-check your answer, by adding 64 + 16 + 4 + 2 = 86

There are probably faster ways of doing it, but I think this is the easiest.

Well, I can't get the numbers to line up right, but I think you get the idea.

[This message has been edited by Matthew Jones (edited February 06, 2001).]

I used Tony's way of getting the answer. One of the ways are wrong, which one could it be?

------------------

I wish there was a button on my monitor to turn up the intellegince.

Theres a button called 'brightness' but it doesn't work

[This message has been edited by Brett Knapik (edited February 06, 2001).]

You are almost there, just a little more formaility. What you want to is iterate through every power of 2 from the largest power that fits down to 1 (2 to the 0 power).

So for 86 (the largest power of two is 6 or 64)

does 64 fit into 86 (yes) so you have a 1 {now subtract 64 from 86}

does 32 fit into 22 (no 32 > 22 ) so you have a 0

does 16 fit into 22 (yes) you have a 1 (subtract 16 from 22)

does 8 fit into 6 (no) you have a 0

does 4 fit into 6 (yes) you have a 1 (subtract 4 from 6 )

does 2 fit into 2 (yes) you have a 1 (subtract 2 from 2)

does 1 fit into 0 (no) you have a 0

were done with 2 to the 0 so we are done (now concatinate the 0's and 1's

1010110

or 64 + 16 + 4 + 2 = 86

72-64 = 8

8-8 = 0

so the answer would be 1001000. ok just one more quick question is there a trick for figuring out negetives and what is this sign bit thing, how can i distinguish that.

------------------

I wish there was a button on my monitor to turn up the intellegince.

Theres a button called 'brightness' but it doesn't work

Start with 86... NOTE R stands for remainder.

1. 86 / 2 = 43 R = 86 % 2 = 0

2. 43 / 2 = 21 R = 42 % 2 = 1

3. 21 / 2 = 10 R = 21 % 2 = 1

4. 10 / 2 = 5 R = 10 % 2 = 0

5. 5 / 2 = 2 R = 5 % 2 = 1

6. 2 / 2 = 1 R = 2 % 2 = 0

7. 1 / 2 = 0 R = 1 % 2 = 1

Writing this answer from #7 to #1 from you get: 1010110.

With 72, you do the same thing.

1. 72 / 2 = 36 R = 72 % 2 = 0

2. 36 / 2 = 18 R = 36 % 2 = 0

3. 18 / 2 = 9 R = 18 % 2 = 0

4. 9 / 2 = 4 R = 9 % 2 = 1

5. 4 / 2 = 2 R = 4 % 2 = 0

6. 2 / 2 = 1 R = 2 % 2 = 0

7. 1 / 2 = 0 R = 1 % 2 = 1

Answer from #7 to #1 is: 1001000.

-Peter

------------------

I wish there was a button on my monitor to turn up the intellegince.

Theres a button called 'brightness' but it doesn't work

To the other part of your question, if you want the negative of a number then get the binary value of the positive value. Negate all bits and add 1. NOTE, carry out any leading 0 to your sign bit. Assuming a byte (8 bits) below.

E.g. From above example, 86 is 01010110. Note my sign bit (position #8 is 0 for positive sign).

1. Get binary result for positive value. 86 -> 01010110.

1. Negate all bits: 10101001.

2. Add 1 -> 10101010 = -86.

Note, since I'm assuming a byte which has 8 bits, my sign bit (bit #8) is now 1.

-Peter