How can I convert Matlab code to c#?

Matlab binary to decimal conversion?

  • using the pseudo code below, what would the matlab code be for Problem 1. Implement in matlab the following functions: 1. function DecimalToBinary (d) 2. function BinaryToDecimal (b) 3. function BinarySum (a1,a2) 4. function BinaryProd (f1,f2) The first function accepts a real number d and converts it into a row vector of 64 binary elements, each either 0 or 1. These 64 binary elements must respect the finite precision binary representation seen in class for real numbers (one sign bit, 11 exponent bits, 52 mantissa bits). The second function does the opposite: given a vector b of 64 binary elements, it returns the corresponding (finite precision) real number. The last two functions return the binary representation (i.e., a binary vector) of the sum (resp. the product) of the two arguments passed, both expressed as vectors of 64 binary elements. Test these functions by running 20 times the following test (turn in the code used for this test): 1. Generate two random numbers n1 and n2, both between −10^8and 10^8. 2. Translate them into two vectors v1 and v2 using DecimalToBinary. 3. Compute their sum and their products using BinarySum and BinaryProd; each will output binary vectors. Call them bsum and bprod. 4. Convert bsum and bprod to decimal using BinaryToDecimal, and check if they are indeed the sum and product of n1 and n2.

  • Answer:

Walt P at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.