Posts

Showing posts with the label right-shift operator

mathajax

Binary to Decimal & Decimal to Binary Bitwise Right-shift Operator

Image
The Java code has two number conversion operations; one is decimal to binary conversion and second binary to decimal conversion . These two operations are done by bitwise right shift operator .  Conditional switch selects the case, one of the two conversion operation is to carry out from choice input given to program.  If choice is 1, switch selects case1 ( binary to decimal conversion ) and if choice is 2, switch selects case2 ( decimal to binary conversion ). Decimal 2 Binary by Right shift  Binary to decimal conversion  Assume that, choice is 1 and switch selects binary to decimal conversion operation. The user is prompted enter 8 binary bits as input which is to be converted into a decimal value . Assume that, binary input given is 011000000 and it is stored into a string object “bstr” and initialize decval  = 0.   Bstr  =”[01100000]”   characters indexed (0,1,2,.)  from left to right  decval =0; the it...