ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Hex.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
15
16using namespace etiss::plugin::gdb::hex;
17
19{
20 if (c <= '9' && c >= '0')
21 {
22 return (uint8_t)(c - '0');
23 }
24 else if (c <= 'f' && c >= 'a')
25 {
26 return (uint8_t)(c - 'a' + 10);
27 }
28 else if (c <= 'F' && c >= 'A')
29 {
30 return (uint8_t)(c - 'A' + 10);
31 }
32 else
33 {
34 return 16;
35 }
36}
38{
39 if (l < 10)
40 {
41 return '0' + (char)l;
42 }
43 else if (l < 16)
44 {
45 return 'A' + (char)l - 10;
46 }
47 else
48 {
49 return '?';
50 }
51}
52
53uint8_t etiss::plugin::gdb::hex::toByte(std::string hex, size_t pos)
54{
55 return toByte(hex[pos], hex[pos + 1]);
56}
58{
59 return fromHex(h) << 4 | fromHex(l);
60}
61
62std::string etiss::plugin::gdb::hex::fromByte(uint8_t byte)
63{
64 std::string ret = " ";
65 ret[0] = toHex(byte >> 4);
66 ret[1] = toHex(byte & 0x0F);
67 return ret;
68}
69
70void etiss::plugin::gdb::hex::fromByte(std::string &append, uint8_t byte)
71{
72 append.push_back(toHex(byte >> 4));
73 append.push_back(toHex(byte & 0x0F));
74}
75
76std::string etiss::plugin::gdb::hex::fromBytes(uint8_t *buf, size_t length)
77{
78 std::string ret;
79 ret.resize(length * 2);
80 for (unsigned i = 0; i < length; i++)
81 {
82 ret[i * 2] = toHex(buf[i] >> 4);
83 ret[i * 2 + 1] = toHex(buf[i] & 0x0F);
84 }
85 return ret;
86}
__device__ __2f16 float c
static __inline__ uint8_t
Definition arm_mve.h:323
uint8_t toByte(char h, char l)
converts 2 hex characters to a byte
Definition Hex.cpp:57
std::string fromByte(uint8_t byte)
converts a byte to a hex string (without "0x" prefix);
Definition Hex.cpp:62
std::string fromBytes(uint8_t *buf, size_t length)
converts a sequence of bytes to a representing hex string (without "0x" prefix)
Definition Hex.cpp:76
uint8_t fromHex(char c)
convert a character to the hex value it represents(0-15)
Definition Hex.cpp:18
char toHex(uint8_t l)
converts the lower 4 bits to a representing char
Definition Hex.cpp:37
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)