aries
aries

Reputation: 909

Inverse of left shift by 1

I have the below equation.

A=B<<1. 

Could some one please tell me how I can get back B given A?

Upvotes: 1

Views: 1207

Answers (2)

gnasher729
gnasher729

Reputation: 52538

You can't. The highest bit of B is lost, and there is no way you can get it back.

Upvotes: 1

Marcinek
Marcinek

Reputation: 2117

You can simply use the right shift operator:

B = A >> 1

Details see

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

and this

Byte shift inverse operation

Upvotes: 0

Related Questions