diff --git a/drivers/CpuUid.cpp b/drivers/CpuUid.cpp index be0efd7f10..da5b9459f2 100644 --- a/drivers/CpuUid.cpp +++ b/drivers/CpuUid.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include #include "hal/cpu_uid_api.h" #include "drivers/CpuUid.h" @@ -22,6 +21,8 @@ namespace mbed { +const char CpuUid::_hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + CpuUid::CpuUid() : _data(NULL) { _size = cpu_uid_get_length(); @@ -43,12 +44,11 @@ CpuUid::~CpuUid() CpuUid::operator std::string() { std::string str; - char buf[3]; for (int i = 0; i < _size; ++i) { - snprintf(buf, 3, "%.2X", _data[i]); - str += buf; + str += _hexChars[_data[i] >> 4]; + str += _hexChars[_data[i] & 0x0F]; } return str; diff --git a/drivers/CpuUid.h b/drivers/CpuUid.h index aa6fea9f79..4336ba85c0 100644 --- a/drivers/CpuUid.h +++ b/drivers/CpuUid.h @@ -87,6 +87,8 @@ public: private: uint8_t * _data; int _size; + + static const char _hexChars[16]; }; } // namespace mbed