@@ -27,14 +27,24 @@ namespace {
27
27
return false ;
28
28
}
29
29
30
- std::byte operator +(const std::byte & lhs, const std::byte &rhs) {
30
+ std::byte operator +(const std::byte lhs, const std::byte &rhs) {
31
31
return std::byte {static_cast <std::uint8_t >(static_cast <int >(lhs) + static_cast <int >(rhs))};
32
32
}
33
33
34
34
// This madness should be removed once the minimum compiler version increases...
35
35
std::byte logicalAnd (const std::byte &lhs, const std::byte &rhs) {
36
36
return std::byte {static_cast <std::uint8_t >(static_cast <int >(lhs) & static_cast <int >(rhs))};
37
37
}
38
+
39
+ // This madness should be removed once the minimum compiler version increases...
40
+ std::byte shiftLeft (const std::byte &lhs, const int rhs) {
41
+ return std::byte {static_cast <std::uint8_t >(static_cast <int >(lhs) << rhs)};
42
+ }
43
+
44
+ // This madness should be removed once the minimum compiler version increases...
45
+ std::byte shiftRight (const std::byte &lhs, const int rhs) {
46
+ return std::byte {static_cast <std::uint8_t >(static_cast <int >(lhs) >> rhs)};
47
+ }
38
48
} // namespace
39
49
40
50
namespace display_device {
@@ -86,12 +96,12 @@ namespace display_device {
86
96
{
87
97
constexpr std::byte ascii_offset {' @' };
88
98
89
- auto byte_a {data[8 ]};
90
- auto byte_b {data[9 ]};
99
+ const auto byte_a {data[8 ]};
100
+ const auto byte_b {data[9 ]};
91
101
std::array<char , 3 > man_id {};
92
102
93
- man_id[0 ] = static_cast <char >(ascii_offset + (logicalAnd (byte_a, std::byte {0x7C }) >> 2 ));
94
- man_id[1 ] = static_cast <char >(ascii_offset + (logicalAnd (byte_a, std::byte {0x03 }) << 3 ) + (logicalAnd (byte_b, std::byte {0xE0 }) >> 5 ));
103
+ man_id[0 ] = static_cast <char >(ascii_offset + shiftRight (logicalAnd (byte_a, std::byte {0x7C }), 2 ));
104
+ man_id[1 ] = static_cast <char >(ascii_offset + shiftLeft (logicalAnd (byte_a, std::byte {0x03 }), 3 ) + shiftRight (logicalAnd (byte_b, std::byte {0xE0 }), 5 ));
95
105
man_id[2 ] = static_cast <char >(ascii_offset + logicalAnd (byte_b, std::byte {0x1F }));
96
106
97
107
for (const char ch : man_id) {
0 commit comments