print decimal numbers
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -25,6 +25,79 @@ const char* to_string(uint64_t value) {
|
|||||||
return uintTo_StringOutput;
|
return uintTo_StringOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char hexTo_StringOutput[128];
|
||||||
|
const char* to_hstring(uint64_t value) {
|
||||||
|
uint64_t* valPtr = &value;
|
||||||
|
uint8_t* ptr;
|
||||||
|
uint8_t temp;
|
||||||
|
uint8_t size = 8*2 - 1;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < size; i++) {
|
||||||
|
ptr = ((uint8_t*)valPtr + i);
|
||||||
|
temp = ((*ptr & 0xF0) >> 4);
|
||||||
|
hexTo_StringOutput[size - (i * 2 + 1)] = temp + (temp > 9 ? 'A' : '0');
|
||||||
|
temp = ((*ptr & 0x0F));
|
||||||
|
hexTo_StringOutput[size - (i * 2)] = temp + (temp > 9 ? 'A' : '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
hexTo_StringOutput[size + 1] = 0;
|
||||||
|
return hexTo_StringOutput;
|
||||||
|
}
|
||||||
|
char hexTo_StringOutput32[128];
|
||||||
|
const char* to_hstring(uint32_t value) {
|
||||||
|
uint32_t* valPtr = &value;
|
||||||
|
uint8_t* ptr;
|
||||||
|
uint8_t temp;
|
||||||
|
uint8_t size = 4*2 - 1;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < size; i++) {
|
||||||
|
ptr = ((uint8_t*)valPtr + i);
|
||||||
|
temp = ((*ptr & 0xF0) >> 4);
|
||||||
|
hexTo_StringOutput32[size - (i * 2 + 1)] = temp + (temp > 9 ? 55 : '0');
|
||||||
|
temp = ((*ptr & 0x0F));
|
||||||
|
hexTo_StringOutput32[size - (i * 2)] = temp + (temp > 9 ? 55 : '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
hexTo_StringOutput32[size + 1] = 0;
|
||||||
|
return hexTo_StringOutput32;
|
||||||
|
}
|
||||||
|
char hexTo_StringOutput16[128];
|
||||||
|
const char* to_hstring(uint16_t value) {
|
||||||
|
uint16_t* valPtr = &value;
|
||||||
|
uint8_t* ptr;
|
||||||
|
uint8_t temp;
|
||||||
|
uint8_t size = 2*2 - 1;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < size; i++) {
|
||||||
|
ptr = ((uint8_t*)valPtr + i);
|
||||||
|
temp = ((*ptr & 0xF0) >> 4);
|
||||||
|
hexTo_StringOutput16[size - (i * 2 + 1)] = temp + (temp > 9 ? 55 : '0');
|
||||||
|
temp = ((*ptr & 0x0F));
|
||||||
|
hexTo_StringOutput16[size - (i * 2)] = temp + (temp > 9 ? 55 : '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
hexTo_StringOutput16[size + 1] = 0;
|
||||||
|
return hexTo_StringOutput16;
|
||||||
|
}
|
||||||
|
char hexTo_StringOutput8[128];
|
||||||
|
const char* to_hstring(uint8_t value) {
|
||||||
|
uint8_t* valPtr = &value;
|
||||||
|
uint8_t* ptr;
|
||||||
|
uint8_t temp;
|
||||||
|
uint8_t size = 1*2 - 1;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < size; i++) {
|
||||||
|
ptr = ((uint8_t*)valPtr + i);
|
||||||
|
temp = ((*ptr & 0xF0) >> 4);
|
||||||
|
hexTo_StringOutput8[size - (i * 2 + 1)] = temp + (temp > 9 ? 55 : '0');
|
||||||
|
temp = ((*ptr & 0x0F));
|
||||||
|
hexTo_StringOutput8[size - (i * 2)] = temp + (temp > 9 ? 55 : '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
hexTo_StringOutput8[size + 1] = 0;
|
||||||
|
return hexTo_StringOutput8;
|
||||||
|
}
|
||||||
|
|
||||||
char intTo_StringOutput[128];
|
char intTo_StringOutput[128];
|
||||||
const char* to_string(int64_t value) {
|
const char* to_string(int64_t value) {
|
||||||
uint8_t isNegative = 0;
|
uint8_t isNegative = 0;
|
||||||
@@ -60,6 +133,10 @@ const char* to_string(int64_t value) {
|
|||||||
|
|
||||||
char doubleTo_StringOutput[128];
|
char doubleTo_StringOutput[128];
|
||||||
const char* to_string(double value, uint8_t decimalPlaces) {
|
const char* to_string(double value, uint8_t decimalPlaces) {
|
||||||
|
if (decimalPlaces > 20) {
|
||||||
|
decimalPlaces = 20;
|
||||||
|
}
|
||||||
|
|
||||||
char* intPtr = (char*)to_string((int64_t)value);
|
char* intPtr = (char*)to_string((int64_t)value);
|
||||||
char* doublePtr = doubleTo_StringOutput;
|
char* doublePtr = doubleTo_StringOutput;
|
||||||
|
|
||||||
@@ -87,4 +164,7 @@ const char* to_string(double value, uint8_t decimalPlaces) {
|
|||||||
|
|
||||||
*doublePtr = 0;
|
*doublePtr = 0;
|
||||||
return doubleTo_StringOutput;
|
return doubleTo_StringOutput;
|
||||||
|
}
|
||||||
|
const char* to_string(double value) {
|
||||||
|
return to_string(value, 2);
|
||||||
}
|
}
|
||||||
@@ -3,4 +3,9 @@
|
|||||||
|
|
||||||
const char* to_string(uint64_t value);
|
const char* to_string(uint64_t value);
|
||||||
const char* to_string(int64_t value);
|
const char* to_string(int64_t value);
|
||||||
const char* to_string(double value, uint8_t decimalPlaces);
|
const char* to_hstring(uint64_t value);
|
||||||
|
const char* to_hstring(uint32_t value);
|
||||||
|
const char* to_hstring(uint16_t value);
|
||||||
|
const char* to_hstring(uint8_t value);
|
||||||
|
const char* to_string(double value, uint8_t decimalPlaces);
|
||||||
|
const char* to_string(double value);
|
||||||
@@ -16,7 +16,15 @@ extern "C" void _start(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) {
|
|||||||
newRenderer.cursorPosition = {0, 18};
|
newRenderer.cursorPosition = {0, 18};
|
||||||
newRenderer.Print(0xFFFFFF, to_string((int64_t)-1234976));
|
newRenderer.Print(0xFFFFFF, to_string((int64_t)-1234976));
|
||||||
newRenderer.cursorPosition = {0, 36};
|
newRenderer.cursorPosition = {0, 36};
|
||||||
newRenderer.Print(0xFFFFFF, to_string(3.141, 2));
|
newRenderer.Print(0xFFFFFF, to_string(-3.141));
|
||||||
|
newRenderer.cursorPosition = {0, 54};
|
||||||
|
newRenderer.Print(0xFFFFFF, to_hstring((uint64_t)0xF0));
|
||||||
|
newRenderer.cursorPosition = {0, 72};
|
||||||
|
newRenderer.Print(0xFFFFFF, to_hstring((uint32_t)0xF0));
|
||||||
|
newRenderer.cursorPosition = {0, 90};
|
||||||
|
newRenderer.Print(0xFFFFFF, to_hstring((uint16_t)0xF0));
|
||||||
|
newRenderer.cursorPosition = {0, 108};
|
||||||
|
newRenderer.Print(0xFFFFFF, to_hstring((uint8_t)0xF0));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user