hex_util.cpp 696 B

123456789101112131415161718192021
  1. // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
  2. // SPDX-FileCopyrightText: 2014 Citra Emulator Project
  3. // SPDX-License-Identifier: GPL-2.0-or-later
  4. #include "common/hex_util.h"
  5. namespace Common {
  6. std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) {
  7. std::vector<u8> out(str.size() / 2);
  8. if (little_endian) {
  9. for (std::size_t i = str.size() - 2; i <= str.size(); i -= 2)
  10. out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
  11. } else {
  12. for (std::size_t i = 0; i < str.size(); i += 2)
  13. out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
  14. }
  15. return out;
  16. }
  17. } // namespace Common