Maipa's Standard Library Extension 1.5.6
mstd
Loading...
Searching...
No Matches
bit_operations.hpp
1/*
2 * mstd - Maipa's Standard Library
3 *
4 * Licensed under the BSD 3-Clause License with Attribution Requirement.
5 * See the LICENSE file for details: https://github.com/MAIPA01/mstd/blob/main/LICENSE
6 *
7 * Copyright (c) 2025, Patryk Antosik (MAIPA01)
8 */
9
10#pragma once
11#ifndef _MSTD_BIT_OPERATIONS_HPP_
12 #define _MSTD_BIT_OPERATIONS_HPP_
13
14 #include <mstd/config.hpp>
15
17_MSTD_WARNING("this is only available for c++17 and greater!");
18 #else
19
20 #include <mstd/arithmetic_types.hpp>
21
22namespace mstd {
23 _MSTD_INLINE17 _MSTD_CONSTEXPR20 uint32_t swap_endians(uint32_t value) noexcept {
24 _MSTD_CONSTEXPR17 const uint32_t first_elem_mask = 0x0000'00FF;
25 _MSTD_CONSTEXPR17 const uint32_t second_elem_mask = 0x0000'FF00;
26 _MSTD_CONSTEXPR17 const uint32_t third_elem_mask = 0x00FF'0000;
27 _MSTD_CONSTEXPR17 const uint32_t forth_elem_mask = 0xFF00'0000;
28
29 _MSTD_CONSTEXPR17 const uint32_t corner_elements_shift = 24;
30 _MSTD_CONSTEXPR17 const uint32_t middle_elements_shift = 8;
31
32 return ((value >> corner_elements_shift) & first_elem_mask) | ((value >> middle_elements_shift) & second_elem_mask) |
33 ((value << middle_elements_shift) & third_elem_mask) | ((value << corner_elements_shift) & forth_elem_mask);
34 }
35} // namespace mstd
36 #endif
37#endif
#define _MSTD_HAS_CXX17
Definition config.hpp:45
#define _MSTD_CONSTEXPR17
Definition config.hpp:76
#define _MSTD_INLINE17
Definition config.hpp:83
#define _MSTD_CONSTEXPR20
Definition config.hpp:84
Definition arithmetic_types.hpp:23
_MSTD_INLINE17 _MSTD_CONSTEXPR20 uint32_t swap_endians(uint32_t value) noexcept
Definition bit_operations.hpp:23