Skip to content

Commit

Permalink
Add uint32_2data utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
higaski committed Jul 9, 2023
1 parent 945ebc2 commit 6a4d4d0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/mdu/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,17 @@ constexpr auto data2uint64(uint8_t const* data) {
return static_cast<uint64_t>(upper) << 32u | lower;
}

/// uint32_t to data
///
/// \param word Word to convert
/// \param data Pointer to write to
/// \return Pointer after last element
constexpr auto uint32_2data(uint32_t word, uint8_t* data) {
*data++ = static_cast<uint8_t>((word & 0xFF00'0000u) >> 24u);
*data++ = static_cast<uint8_t>((word & 0x00FF'0000u) >> 16u);
*data++ = static_cast<uint8_t>((word & 0x0000'FF00u) >> 8u);
*data++ = static_cast<uint8_t>((word & 0x0000'00FFu) >> 0u);
return data;
}

} // namespace mdu

0 comments on commit 6a4d4d0

Please sign in to comment.