944,148 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 11607
  • C++ RSS
Apr 27th, 2007
0

Binary String in to Integer in c++

Expand Post »
hi

I want convert Binary String to intger Format in c++.
like "00000100" should give me as "04" or "4"
could anyone suggest me the solution for it.

thanks
Mukesh
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MukeshZ is offline Offline
17 posts
since Apr 2007
Apr 27th, 2007
0

Re: Binary String in to Integer in c++

construct a bitset using the string and then convert it to a ulong.
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. #include <bitset>
  4. #include <limits>
  5. using namespace std ;
  6.  
  7. int main()
  8. {
  9. string str = "00000100" ;
  10. cout << bitset<numeric_limits<unsigned long>::digits>(str).to_ulong()
  11. << '\n' ;
  12. }
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Permutaions With Recursion
Next Thread in C++ Forum Timeline: How to fit integer in format......





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC