Ask Your Question
1

How can you perform division of a number by 3 without utilizing arithmetic operators such as multiplication, division, addition, subtraction or modulus?

asked 2023-05-21 23:25:03 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-21 23:44:02 +0000

devzero gravatar image

One way to perform division of a number by 3 without utilizing arithmetic operators such as multiplication, division, addition, subtraction or modulus is by using bit manipulation.

Here's the algorithm:

  1. Right-shift the input number by 1 bit (i.e. divide by 2)
  2. Add the original number to the result of step 1 (i.e. multiply by 2/shifted by 1 bit)
  3. Right-shift the result of step 2 by 1 bit (i.e. divide by 2 again)
  4. Repeat steps 2-3 until the result is less than 3

The final result will be the quotient of the original number divided by 3.

Here's an example: Let's consider the number 9

  1. Right-shift 9 by 1 bit: 1001 -> 0100 (4 in decimal)
  2. Add 9 to 4: 9 + 4 = 13
  3. Right-shift 13 by 1 bit: 1101 -> 0110 (6 in decimal)
  4. 6 is less than 3, so the quotient of 9 divided by 3 is equal to 2.

Therefore, the answer is 2.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-21 23:25:03 +0000

Seen: 12 times

Last updated: May 21 '23