Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Can anyone help me on c#

A user should be able to enter a Binary number and then your program will convert it into Denary and output the result.


The entered number can be any length.



I have no clue how to do this ???

Answers

  • I hope its not too late and hope this helps, I will be back home in a while and then give you a bigger reply.

  • I don't quite understand how to make the int[] denaryPlaceValues but I took a look around and here is the link to the answer. The answer is by Adam Modlin.

    First, We declared two variables m and result. m is just there to assign the correct place values for the binary and result will be keeping our result. Then we get input from the user. Then convert that input into two arrays, one for binary and the other for denary. Then, in the first for loop, we generate the binary place values based on how big the number is. The two foreach loops just write the values, you can cut that out, I just added it for display. In the last for loop, we have two integers a and b. a gets the value from the last of the binaryPlaceValues array and b gets the value from the beginning of the denaryPlaceValues array. The third integer, currentValue, multiples a and b and stores their value. Then in the end, currentValue is assigned to result. And then we output that result.

    I know that there might be a better way to do this but I hope this helps.

Sign In or Register to comment.