0

reverse a given number only using bitwise operation e.g.: input: 4532 output : 2354 I'm not able to think of any bitwise operations to tackle this question.Any solution/assistance would be of great help. The division and modulo by 10 needs to be performed using bitwise operations only.

7
  • 1
    Does this answer your question? Reversing a Number using bitwise shift Commented Sep 23, 2020 at 18:07
  • 4
    Are you sure you need to reverse the number in base 10 (as opposed to binary) using bitwise (as opposed to basic arithmetic) operations? I'm pretty sure there is no elegant way of doing that. Commented Sep 23, 2020 at 18:30
  • 1
    Does "only using bitwise operation" mean not using for, while, if, ... ? please explain what does it mean? Commented Sep 23, 2020 at 18:46
  • 1
    You can do it with bitwise operations, but you need to implement division_by_10_with_remainder using shift/compare/subtract. All of those can be done in bitwise fashion, and we'll see you next month ;) Commented Sep 23, 2020 at 21:00
  • 3
    en.wikipedia.org/wiki/Double_dabble and cypress.com/file/42131/download Commented Sep 24, 2020 at 7:49

1 Answer 1

0

there's no efficient way of reversing a number using only bitwise operators (mostly shift operators). But we can use BCD conversion to convert the integer to BCD and then reverse using shift operators. So after BCD conversion we can shift every set of 4 bits (representing a digit ranging from 0-9) step wise in the opposite order, to get the reversed Number in BCD format.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.