Espacios de nombres
Variantes
Acciones

std::bitset

De cppreference.com
< cpp‎ | utility
 
 
Biblioteca de servicios
Servicios generales
Operadores relacionales (en desuso en C++20)
 
std::bitset
Tipos de miembros
Original:
Member types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Elemento acceso
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Capacidad
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modificadores
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Conversiones
Original:
Conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Terceros funciones
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Clases de ayuda
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
 
Definido en el archivo de encabezado <bitset>
template< std::size_t N >
class bitset;

La plantilla de clase std::bitset representa una secuencia de tamaño fijo de N bits. Un conjunto de bits puede ser manipulado por operadores lógicos habituales, y convertido hacia y desde strings y números enteros.

std::bitset cumple los requisitos de CopyConstructible y CopyAssignable .

Contenido

[editar] Parámetros de plantilla

N - El número de bits para los cuales se asigna almacenamiento

[editar] Tipos miembro

clase proxy que representa una referencia a un bit
(clase)

[editar] Funciones miembro

construye el bitset
Original:
constructs the bitset
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
compara el contenido
(función miembro pública) [editar]
Acceso a elementos
acceso a un bit específico
(función miembro pública) [editar]
accede a poco específica
Original:
accesses specific bit
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
(C++11)  
Verifica si todos, alguno o ninguno de los bits se establecen en true
Original:
checks if all, any or none bits are set to true
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
devuelve el número de bits puestos en true
Original:
returns the number of bits set to true
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
Capacidad
devuelve el número del tamaño de bits que el bitset puede contener
Original:
returns the size number of bits that the bitset can hold
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
Modificadores
realiza operación binaria AND, OR, XOR y NOT
(función miembro pública) [editar]
realiza izquierda binario desplazamiento y desplazamiento a la derecha
Original:
performs binary shift left and shift right
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
sets bits to true or given value
(función miembro pública) [editar]
establece bits a false
Original:
sets bits to false
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
Alterna entre los valores de los bits
(función miembro pública) [editar]
Conversiones
devuelve una representación de cadena de los datos
Original:
returns a string representation of the data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
devuelve una representación entera unsigned long de los datos
Original:
returns an unsigned long integer representation of the data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]
(C++11)
devuelve una representación entera unsigned long long de los datos
Original:
returns an unsigned long long integer representation of the data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro pública) [editar]

[editar] Funciones no-miembro

Realiza operaciones lógicas binarias en conjuntos de bits.
(función) [editar]
Realiza entrada y salida de flujos de conjuntos de bits.
(función) [editar]

[editar] Clases auxiliares

Apoyo de generación de dispersión para std::bitset.
(especialización de plantilla de clase) [editar]

[editar] Notas

Si el tamaño del std::bitset no es conocido en tiempo de compilación entonces es posible que se use std::vector<bool> o boost::dynamic_bitset.

[editar] Ejemplo

#include <bitset>
#include <cassert>
#include <iostream>
 
int main()
{
    // constructores:
    constexpr std::bitset<4> b1;
    constexpr std::bitset<4> b2{0xA}; // == 0B1010
    std::bitset<4> b3{"0011"}; // no puede ser constexpr por ahora
    std::bitset<8> b4{"ABBA", /*longitud*/4, /*0:*/'A', /*1:*/'B'}; // == 0B0000'0110
 
    // bitsets pueden insertarse a un flujo:
    std::cout << "b1:" << b1 << "; b2:" << b2 << "; b3:" << b3 << "; b4:" << b4 << '\n';
 
    // bitset soporta operaciones bit a bit:
    b3 |= 0b0100; assert(b3 == 0b0111);
    b3 &= 0b0011; assert(b3 == 0b0011);
    b3 ^= std::bitset<4>{0b1100}; assert(b3 == 0b1111);
 
    // operaciones sobre todo un conjunto:
    b3.reset(); assert(b3 == 0);
    b3.set(); assert(b3 == 0b1111);
    assert(b3.all() && b3.any() && !b3.none());
    b3.flip(); assert(b3 == 0);
 
    // operaciones en bits individuales:
    b3.set(/*   posición = */ 1, true); assert(b3 == 0b0010);
    b3.set(/*   posición = */ 1, false); assert(b3 == 0);
    b3.flip(/*  posición = */ 2); assert(b3 == 0b0100);
    b3.reset(/* posición = */ 2); assert(b3 == 0);
 
    // El operador de subíndice operator[] es soportado:
    b3[2] = true; assert(true == b3[2]);
 
    // otras operaciones:
    assert(b3.count() == 1);
    assert(b3.size() == 4);
    assert(b3.to_ullong() == 0b0100ULL);
    assert(b3.to_string() == "0100");
}

Salida:

b1:0000; b2:1010; b3:0011; b4:00000110

[editar] Ver también

Conjunto de bits eficiente en el uso de espacio.
(plantilla de clase) [editar]