Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Sergey Alexandrovich Kryukov 25-Mar-14 3:03am    
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!?

C#
int i = Convert.ToInt32("00010010", 2);
 
Share this answer
 
For converting from binary to decimal you could do it like in the next code:
C#
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))
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900