-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbyte.cpp
More file actions
34 lines (28 loc) · 695 Bytes
/
byte.cpp
File metadata and controls
34 lines (28 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Source: http://www.nuonsoft.com/blog/2018/06/03/c17-stdbyte/
#include <iostream>
#include <cstddef>
using namespace std;
void PrintByte(const byte& aByte)
{
cout << to_integer<int>(aByte) << endl;
}
int main()
{
if(true ){
byte myByte{ 2 };
PrintByte(myByte); // 2
// A 2-bit left shift
myByte <<= 2;
PrintByte(myByte); // 8
// Initialize two new bytes using binary literals.
byte byte1{ 0b0011 };
byte byte2{ 0b1010 };
PrintByte(byte1); // 3
PrintByte(byte2); // 10
// Bit-wise OR and AND operations
byte byteOr = byte1 | byte2;
byte byteAnd = byte1 & byte2;
PrintByte(byteOr); // 11
PrintByte(byteAnd); // 2
}
}