diff --git a/prototypes/base/include/console.hpp b/prototypes/base/include/console.hpp index 12453aa..5b9879e 100644 --- a/prototypes/base/include/console.hpp +++ b/prototypes/base/include/console.hpp @@ -59,6 +59,11 @@ private: * Moves the hardware caret. */ void updateCaret(); + + /** + * Prints the prefix for a given numeric base. + */ + void printNumericPrefix(uint32_t base); public: Console(Screen *screen); diff --git a/prototypes/base/src/console.cpp b/prototypes/base/src/console.cpp index a27f1b0..27f8602 100644 --- a/prototypes/base/src/console.cpp +++ b/prototypes/base/src/console.cpp @@ -168,6 +168,7 @@ template<> Console & Console::operator << (const NumericFormat & fmt) { char buffer[13]; + this->printNumericPrefix(fmt.base); size_t len = Numeric::toString(buffer, sizeof(buffer), fmt.value, fmt.base); for(size_t i = 0; i < len; i++) { this->put(buffer[i]); @@ -179,6 +180,7 @@ template<> Console & Console::operator << (const NumericFormat & fmt) { char buffer[13]; + this->printNumericPrefix(fmt.base); size_t len = Numeric::toString(buffer, sizeof(buffer), fmt.value, fmt.base); for(size_t i = 0; i < len; i++) { this->put(buffer[i]); @@ -190,6 +192,7 @@ template<> Console & Console::operator << (const NumericFormat & fmt) { char buffer[13]; + this->printNumericPrefix(fmt.base); size_t len = Numeric::toString(buffer, sizeof(buffer), fmt.value, fmt.base); for(size_t i = 0; i < len; i++) { this->put(buffer[i]); @@ -201,9 +204,23 @@ template<> Console & Console::operator << (const NumericFormat & fmt) { char buffer[13]; + this->printNumericPrefix(fmt.base); size_t len = Numeric::toString(buffer, sizeof(buffer), fmt.value, fmt.base); for(size_t i = 0; i < len; i++) { this->put(buffer[i]); } return *this; +} + +void Console::printNumericPrefix(uint32_t base) +{ + switch(base) { + case 2: *this << "0b"; break; + case 8: *this << "0o"; break; + case 10: return; + case 16: *this << "0x"; break; + default: + *this << "[" << base << "]x"; + break; + } } \ No newline at end of file