converting Binary Numbers in to decimal numbers

前端 未结 6 669
情歌与酒
情歌与酒 2021-01-28 23:42

I need a program to convert Binary numbers into Decimal number in Java or in C++.

is there some one who can help me.

6条回答
  •  面向向阳花
    2021-01-29 00:25

    Use binary expansion. For example 1101 1001 is:

    (1 x 2^7) + (1 x 2^6) + (1 x 2^4) + (1 x 2^3) + (1 x 2^0)

    which is equal to:

    217 in decimal.

    Here is the algorithm:

    1.) Prompt the user for a binary number.

    2.) Store the number in an array. The first element i.e. anArray[0] should contain a value of 1, the second element should have a value of 0 . . .

    3.) Implement a for loop to do the calculation.

提交回复
热议问题