aboutsummaryrefslogtreecommitdiffstats
path: root/src/fp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fp.cpp')
-rw-r--r--src/fp.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/fp.cpp b/src/fp.cpp
index a9e1a7a..7de679c 100644
--- a/src/fp.cpp
+++ b/src/fp.cpp
@@ -9,6 +9,8 @@
#include "proto.hpp"
#include "low_func_llvm.hpp"
#endif
+#include <cybozu/atoi.hpp>
+#include <cybozu/itoa.hpp>
#ifdef _MSC_VER
#pragma warning(disable : 4127)
@@ -135,6 +137,34 @@ void UnitToHex(char *buf, size_t maxBufSize, Unit x)
#endif
}
+// "123af" => { 0xaf, 0x23, 0x01 }
+std::string hexStrToLittleEndian(const char *buf, size_t bufSize)
+{
+ std::string s;
+ s.reserve((bufSize + 1) / 2);
+ while (bufSize >= 2) {
+ uint8_t c = cybozu::hextoi(&buf[bufSize - 2], 2);
+ s += char(c);
+ bufSize -= 2;
+ }
+ if (bufSize == 1) {
+ uint8_t c = cybozu::hextoi(&buf[0], 1);
+ s += char(c);
+ }
+ return s;
+}
+
+// { 0xaf, 0x23, 0x01 } => "0123af"
+std::string littleEndianToHexStr(const char *buf, size_t bufSize)
+{
+ std::string s;
+ s.resize(bufSize * 2);
+ for (size_t i = 0; i < bufSize; i++) {
+ cybozu::itohex(&s[i * 2], 2, (uint8_t)buf[bufSize - 1 - i], false);
+ }
+ return s;
+}
+
bool isEnableJIT()
{
#if defined(MCL_USE_XBYAK)