i have 2 question that i need help to solve

1. write an algorithm that writes the binary form of a decimal number n

2. if d divides both n and m the d divides their sum and d divides their difference

Printable View

- Dec 14th 2007, 03:22 AMmonkyshinesneed help !!
i have 2 question that i need help to solve

1. write an algorithm that writes the binary form of a decimal number n

2. if d divides both n and m the d divides their sum and d divides their difference - Dec 14th 2007, 05:40 AMSoroban
Hello, monkyshines!

Quote:

$\displaystyle \text{2. If }d\text{ divides both }m\text{ and }n\text{, then }d\text{ divides }m+n\text{ and }m-n.$

$\displaystyle \text{Since }d\text{ divides }m\text{, then: }\:m \:= \:da\text{, for some integer }a.$

$\displaystyle \text{Since }d\text{ divides }n\text{, then: }\:n \:= \:db\text{, for some integer }b.$

$\displaystyle \text{Their sum is: }m+n \:=\:da + db \:=\:d(a+b)\text{, which is divisible by }d.$

$\displaystyle \text{Their difference is: }m-n \:=\:da-db \:=\:d(a-b)\text{, which is divisible by }d.$

- Dec 14th 2007, 06:11 AMSoroban
Hello, monkyshines!

Quote:

1. Write an algorithm that writes the binary form of a decimal number $\displaystyle n.$

There is a procedure for this, based on the Euclidean Algorithm.

Example: Convert 87 to binary.

[1] Divide by 2, note the remainder.

. . .$\displaystyle 87 \div 2 \:=\:43\quad \text{Rem . 1}$

[2] Divide the*quotient*by 2, note the remainder.

. . .$\displaystyle 43 \div 2 \:=\:21\quad \text{Rem. 1}$

[3] Repeat step [2] until a zero quotient is reached.

. . .$\displaystyle \begin{array}{cccc}21 \div 2 &=&10 & \text{Rem. 1} \\

10 \div 2 &=& 5 & \text{Rem. 0} \\

5 \div 2 &=& 2 & \text{Rem. 1} \\

2 \div 2 &=&1 & \text{Rem. 0} \\

1 \div 2 &=&0 &\text{Rem. 1} \end{array}$

[4] Now read**up**$\displaystyle (\uparrow)$ the remainders.

Therefore: .$\displaystyle 87_{10} \;=\;1,010,111_2$

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

A silly but true story . . .

Years ago, I gave this exact problem on an exam.

One of my top students (with a quirky sense of humor) wrote

. . "Hi-yo, Silver!" next to his (correct) answer.

Of course, when I handed the papers back, I asked him about it.

He said, "Did you*read*the number?"

Puzzled, I mentally thought: "One-zero-one-zero-one-one-one."

OMG ... It's the opening of*The William Tell Overture !*

(I said he was quirky, didn't I?)