--- Represent/Hexadecimal.cpp 2004/12/22 07:19:54 371 +++ Represent/Hexadecimal.cpp 2004/12/23 01:27:28 373 @@ -6,6 +6,11 @@ #include "Hexadecimal.hpp" +inline byte_t Hexadecimal::hex(const ext::CodePoint& atom) +{ + if (atom >= '0' && atom <= '9') return atom - '0'; else if (atom >= 'a' && atom <= 'f') return atom - 'a' + 0xA; else if (atom >= 'A' && atom <= 'F') return atom - 'A' + 0xA; else return 0; +} + Hexadecimal::Hexadecimal(const ext::String& string, bool signed_) : Binary(string.GetSize() / 2, 0) { if (string.IsEmpty()) @@ -17,22 +22,14 @@ Hexadecimal::Hexadecimal(const ext::Stri size_t index(string.GetSize() % 2), offset(index); - _rmforeach (ext::Vector, byte, bytes) _rfor (byte_t, half, 0, 2) - { -/* byte_t hex(string[index++]); - - if (hex >= '0' && hex <= '9') hex -= '0'; else*/ - } + _rmforeach (ext::Vector, byte, bytes) _rfor (byte_t, half, 0, 2) *byte |= hex(string[index++]) << half * 4; if (offset != 0) { bytes.InsertLast(0); - // - - index = 0; - - // + bytes.Last() |= hex(string[0]); + bytes.Last() |= signed_ && bytes.Last() < 8 ? 0xF0 : 0; } } @@ -44,35 +41,7 @@ Hexadecimal::operator ext::String() cons { byte_t hex(0xF & *byte >> half * 4); - switch (hex) - { - case 0xA: - hex = 'A'; - - break; - case 0xB: - hex = 'B'; - - break; - case 0xC: - hex = 'C'; - - break; - case 0xD: - hex = 'D'; - - break; - case 0xE: - hex = 'E'; - - break; - case 0xF: - hex = 'F'; - - break; - default: - hex += '0'; - } + if (hex < 0xA) hex += '0'; else hex += 'A' - 0xA; string.InsertLast(hex); }