Click here to Skip to main content
14,573,479 members
Rate this:
Please Sign up or sign in to vote.
See more:
i have two binary value like 0001 and 0010 and perform in string format like 00010010 and convert to decimal i am using mvc with razor plz help me?
Posted
Comments
   
How can elementary calculations depend on MVC or Razor? Do you know about Separation of Concerns?
What have you tried so far?
—SA
Punamchand Dhuppad 25-Mar-14 3:10am
   
0001 - 1 and 0010 - 2 then 00010010 - 18. So what do you want ?
Either 18 or ("0001" + "0010") "12"
Raul Iloc 25-Mar-14 15:02pm
   
You request was for converting to "decimal" (not to "int") and for using from razor code, I provided my solution (solution 2) that match all condition at most at the same time with OriginalGriff (that was faster then me but his solution not fulfill your requests). I am wandering why you din not accept my solution!?
Rate this:
Please Sign up or sign in to vote.

Solution 1

int i = Convert.ToInt32("00010010", 2);
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

For converting from binary to decimal you could do it like in the next code:
string temp = "00010010";
decimal myDecimal = Convert.ToInt64(temp,2);


If you really want to do your conversion into a view you should do it in a code block @{ ...} or by using
@(myDecimal = Convert.ToInt64(temp,2))
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100