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

This is for my class in my Computer Science major.

For example, convert 768 to binary. I don't know how to do that without going online and using an online decimal-to-binary converter.
Can someone please tell me a way to do this without aid?

2007-01-18 13:30:14 · 6 answers · asked by diaoman 1 in Computers & Internet Programming & Design

6 answers

Just keep dividing by 2 and putting the remainder into the next empty place.

To use a shorter example,
13/2 = 6, remainder 1
6/2 = 3, remainder 0
3/2 = 1, remainder 1
1/2 = 0, remainder 1
So 13 decimal = 1011 binary.

This approach works with conversion to any base and is easily implemented as an algorithm.

2007-01-18 13:51:19 · answer #1 · answered by injanier 7 · 1 0

Just as each column in a decimal number represents multiples of 10, each column in a binary number represents multiples of 2:

Columns:
1024 512 256 128 64 32 16 8 4 2 1

First, find the largest column value your target number can be divided by. 1024 is out of range, but 768 can be divided by 512 once, so enter '1' in the 512 column.

Next, subtract 512 from 768. The remainder is 256.

Which colum value can now be divided into the remainder? As luck has it, the new target value can be divided one time evenly, with no remainder, by the 256 column. So enter a '1' in the 256 column, and zeros in all remaining columns to the right (align 1 and 0 values with columns in this display).

512 256 128 64 32 16 8 4 2 1
1 1 0 0 0 0 0 0 0 0

So 768 decimal = 1100000000 binary.

I hope I've described this in a way that's understandable!

2007-01-18 13:55:22 · answer #2 · answered by Ed 3 · 0 0

The other suggestions are correct, but there's another algorithm that can be used as well (Edit: whoops, didn't see injanier's answer there). To use it, you need to keep two things in mind:

1) The least significant bit of a binary number is 0 if the number is even, or 1 if it is odd.

2) Shifting a binary number one position to the right (and dropping the old least significant digit in the process) is equivalent to dividing by two and dropping the fractional part (after the decimal point).

768 is even, so write a zero over the right of a piece of paper. The least significant bit is 0. Divide 768 by 2 to get 384. 384 is even, so write a zero to the left of that other zero. Divide 384 by 2 to get 192. 192 is even, so write a zero, and so on...

768 -> 0
384 -> 0
192 -> 0
96 -> 0
48 -> 0
24 -> 0
12 -> 0
6 -> 0
3 -> 1
1 -> 1 (3/2 = 1.5, but remember we're only interested in whole numbers)

So, 768 decimal is 11 0000 0000 in binary!

Another neat trick is to convert the decimal number to hexadecimal, then convert the hex number to binary. Each hexadecimal digit corresponds to a four-bit nybble.

2007-01-18 16:40:53 · answer #3 · answered by watsonc64 3 · 0 0

You have to know the powers of 2 and then subtract down
2,4,8,16,32,64,128,256, 512,
768
512 can be taken from it, so mark 1 in the 512 slot leaving
256
256 can be taken from it, so mark 1 in the 256 slot giving 11
that leaves 0, so all the other slots are 0 =
11000000
52163142
152416
268

2007-01-18 13:41:02 · answer #4 · answered by Mike1942f 7 · 1 0

1. Start => All Programs => Accessories => Calculator.
2. View => Scientific
3. Click the radio option "Dec" in the section at the top left.
4. Type in some decimal numbers. In the result box should say "768.".
5. Click the radio option "Bin" in the section at the top left. The result box should now say "1100000000".
6. Tada.

2007-01-18 13:49:35 · answer #5 · answered by the DtTvB 3 · 1 0

http://www.cs.uaf.edu/~cs301/notes/Chapter3/node7.html

2007-01-18 13:36:44 · answer #6 · answered by csanon 6 · 1 0

fedest.com, questions and answers