determine odd number pattern?

367 Views Asked by At

How can I determine series of such numbers which when keep dividing by 2 always produce odd quotient?
For example: 15
15/2 = 7 (odd) (take only integer(floor) part)
7/2 = 3 (again odd)
3/2 = 1 (again odd)
That's it.
Is there any other way(rather than keep dividing by 2) to know whether a number follows above property or not?

1

There are 1 best solutions below

0
On BEST ANSWER

Write the number in binary. When you divide by $2$, you’re simply shifting the digits one place to the right; if you keep only the integer part, you’re just throwing away the last digit. For example, $15$ in binary is $1111$; dividing by $2$ leaves $111$ (i.e., $7$), dividing by $2$ again leaves $11$ (i.e., $3$), and dividing by $2$ a final times leaves $1$. This is entirely analogous to what happens in ordinary decimal notation when you divide by $10$: you just shift everything one place to the right, and if you’re keeping only the integer part, you throw away the righthand digit.

A number written in binary is odd if and only if it ends in $1$, so you get an odd number every time if and only if your original number is of the form

$$\underbrace{11\ldots11}_{n\text{ ones}}$$

for some $n\ge 1$. But

$$\underbrace{11\ldots11}_{n\text{ ones}}=1\underbrace{00\ldots00}_{n\text{ zeros}}-1=2^n-1\;,$$

so the integers with the desired properties are those that are one less than a power of $2$.