|
Last change
on this file since 47 was
29,
checked in by landauf, 17 years ago
|
|
updated boost from 1_33_1 to 1_34_1
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | // (C) Copyright Jeremy Siek 2001. |
|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. (See |
|---|
| 3 | // accompanying file LICENSE_1_0.txt or copy at |
|---|
| 4 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 5 | // |
|---|
| 6 | // Sample output: |
|---|
| 7 | // mask = 101010101010 |
|---|
| 8 | // Enter a 12-bit bitset in binary: 100110101101 |
|---|
| 9 | // x = 100110101101 |
|---|
| 10 | // As ulong: 2477 |
|---|
| 11 | // And with mask: 100010101000 |
|---|
| 12 | // Or with mask: 101110101111 |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include <iostream> |
|---|
| 16 | #include <boost/dynamic_bitset.hpp> |
|---|
| 17 | |
|---|
| 18 | int main(int, char*[]) { |
|---|
| 19 | const boost::dynamic_bitset<> mask(12, 2730ul); |
|---|
| 20 | std::cout << "mask = " << mask << std::endl; |
|---|
| 21 | |
|---|
| 22 | boost::dynamic_bitset<> x(12); |
|---|
| 23 | std::cout << "x.size()=" << x.size() << std::endl; |
|---|
| 24 | |
|---|
| 25 | std::cout << "Enter a 12-bit bitset in binary: " << std::flush; |
|---|
| 26 | if (std::cin >> x) { |
|---|
| 27 | std::cout << "input number: " << x << std::endl; |
|---|
| 28 | std::cout << "As unsigned long: " << x.to_ulong() << std::endl; |
|---|
| 29 | std::cout << "And with mask: " << (x & mask) << std::endl; |
|---|
| 30 | std::cout << "Or with mask: " << (x | mask) << std::endl; |
|---|
| 31 | std::cout << "Shifted left: " << (x << 1) << std::endl; |
|---|
| 32 | std::cout << "Shifted right: " << (x >> 1) << std::endl; |
|---|
| 33 | } |
|---|
| 34 | return EXIT_SUCCESS; |
|---|
| 35 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.