Spec-Zone.ru › C++

Ключевое слово C++: bitand

Использование

  • альтернативные операторы: как альтернатива &

Пример

#include <bitset>
#include <iostream>

using bin = std::bitset<8>;

void show(bin z, const char* s, int n)
{
    if (n == 0) std::cout << "┌────────────┬──────────┐\n";
    if (n <= 2) std::cout << "│ " <<s<<  " │ " <<z<<" │\n";
    if (n == 2) std::cout << "└────────────┴──────────┘\n";
}

int main()
{
    bin x{"01011010"};  show(x, "x         ", 0);
    bin y{"00111100"};  show(y, "y         ", 1);
    bin z = x bitand y; show(z, "x bitand y", 2);
}

Вывод:

┌────────────┬──────────┐
│ x          │ 01011010 │
│ y          │ 00111100 │
│ x bitand y │ 00011000 │
└────────────┴──────────┘

См. также

  • and, and_eq
  • bitor
  • not, not_eq
  • or, or_eq
  • xor, xor_eq

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/keyword/bitand

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API