GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::bitset::to_ulong(3) C++ Standard Libary std::bitset::to_ulong(3)

std::bitset::to_ulong - std::bitset::to_ulong


unsigned long to_ulong() const (until C++23)
constexpr unsigned long to_ulong() const (since C++23)


Converts the contents of the bitset to an unsigned long integer.


The first bit of the bitset corresponds to the least significant digit of the number
and the last bit corresponds to the most significant digit.


(none)


the converted integer


throws std::overflow_error if the value can not be represented in unsigned long.

// Run this code


#include <iostream>
#include <stdexcept>
#include <bitset>


int main()
{
for (unsigned long i = 0; i < 10; ++i) {
std::bitset<5> b(i);
std::bitset<5> b_inverted = ~b;
std::cout << i << '\t' << b << '\t' << b_inverted << '\t'
<< b_inverted.to_ulong() << '\n';
}


std::cout << std::bitset<32>().to_string('-') << '\n';


try {
std::bitset<128> x(42);
std::cout << x.to_ulong() << '\n';
x.flip();
std::cout << x.to_ulong() << '\n'; // throws
} catch (const std::overflow_error& ex) {
std::cout << "ex: " << ex.what() << '\n';
}
}


0 00000 11111 31
1 00001 11110 30
2 00010 11101 29
3 00011 11100 28
4 00100 11011 27
5 00101 11010 26
6 00110 11001 25
7 00111 11000 24
8 01000 10111 23
9 01001 10110 22
--------------------------------
42
ex: bitset to_ulong overflow error


to_string returns a string representation of the data
(public member function)
to_ullong returns an unsigned long long integer representation of the data
(C++11) (public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.