C++ Standard Library C++ STL Library

C++ <bitset> - to_ullong() Function



The C++ bitset::to_ullong function returns an unsigned long long with the integer value which has the same bit representation as the given bitset.

Syntax

unsigned long long to_ullong() const;

Parameters

No parameter is required.

Return Value

An integer value which has the same bit representation as the given bitset.

Exception

Throws overflow_error, if the bitset size is too big to be represented by the return type.

Example:

The example below shows the usage of bitset::to_ullong function.

#include <iostream>
#include <bitset>
using namespace std;
 
int main (){
  bitset<10> bset("1110000111");

  //converting bset into unsigned long long integer
  unsigned long long i = bset.to_ullong();
  cout<<bset<<" as unsigned long long integer is "<<i<<".\n";

  return 0;
}

The output of the above code will be:

1110000111 as unsigned long long integer is 903.

❮ C++ <bitset> Library