Posts

Showing posts with the label decimal number system

mathajax

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

Image
The Java code has two number conversion operations; first is decimal to binary conversion and second binary to decimal conversion . The bitwise left shift operator used in these both operation.  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). 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 01100000 and it is stored into a string object “bstr” and initialize decval  = 0. bstr  =”[01100000]”  index start 0 from left to right. decval =0; iteration  n=0 decval   = decval <<1;     decval leftshift by 1 bit (re...

Decimal to binary and Binary to decimal

The number system conversion process is carried out between base 10 and base 2 number system . The base 10 number system has 10 distinct numbers from 0 to 9 is called decimal number system and the base 2 number system has 2 distinct numbers 0 and 1 is binary number system . Decimal to binary (base 10 to base 2) conversion - algorithm Given a decimal value, decval and converts it into binary bits modulus decval by 2, it returns a reminder ( 0 or 1) divide decval by 2, it returns a quotient the quotient becomes the decval and repeat step 1 to 3 until decval becomes 0 the reminders on each iteration is results of binary bits Decimal to binary (base 10 to base 2) conversion - Example Given decimal value = 47 ,convert it into binary bits divide the decimal value by 2 returns a quotient and ...