Thread: Bitset

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    34

    Bitset

    Id like to determine the output of this code. I've never used bitset before.
    Code:
    #include <iostream>
     #include <bitset> 
     using namespace std; 
    
     int main() { 
     
     bitset<8> bits = 83;  
     cout << bits << "  ";
     cout << bits.to_ulong() << endl << endl;
    
    
       bits[0] = 0;   
     cout << bits << "  ";  
     cout << bits.to_ulong() << endl << endl;   
    
     bits[1] = 0;   
     cout << bits << "  ";  
     cout << bits.to_ulong() << endl << endl;   
     return 0;
     }

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    98
    system("PAUSE");
    return 0;

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    01010011  83
    
    01010010  82
    
    01010000  80
    Here's the first set of bits vertically from left to right
    0 -- value 128
    1 -- value 64
    0 -- value 32
    1 -- value 16
    0 -- value 8
    0 -- value 4
    1 -- value 2
    1 -- value 1

    So the total of the set bits is 1+2+16+64=83. Make sense?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitset help
    By Kristyy_mariee in forum C++ Programming
    Replies: 1
    Last Post: 03-02-2012, 10:33 PM
  2. bitset problem
    By Ingersoll in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2009, 04:32 AM
  3. bitset + memcpy
    By KBriggs in forum C++ Programming
    Replies: 7
    Last Post: 08-14-2009, 01:04 PM
  4. Bitset questions
    By serge in forum C++ Programming
    Replies: 17
    Last Post: 05-07-2008, 02:00 PM
  5. possible to have pointers in bitset?
    By franziss in forum C++ Programming
    Replies: 23
    Last Post: 04-07-2007, 10:19 PM

Tags for this Thread