Implementing and using ultoa (unsigned long to string)
This commit is contained in:
parent
76c9075f71
commit
743b22ccd6
3 changed files with 28 additions and 2 deletions
4
kernel.c
4
kernel.c
|
@ -58,10 +58,10 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
|
||||||
if (mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
|
if (mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
|
||||||
vga_write("\nFramebuffer: ");
|
vga_write("\nFramebuffer: ");
|
||||||
vga_write("address: 0x");
|
vga_write("address: 0x");
|
||||||
vga_write(ltoa(mbootinfo->framebuffer_addr, 16));
|
vga_write(ultoa(mbootinfo->framebuffer_addr, 16));
|
||||||
serial_write_string("\nFramebuffer: ");
|
serial_write_string("\nFramebuffer: ");
|
||||||
serial_write_string("address: 0x");
|
serial_write_string("address: 0x");
|
||||||
serial_write_string(ltoa(mbootinfo->framebuffer_addr, 16));
|
serial_write_string(ultoa(mbootinfo->framebuffer_addr, 16));
|
||||||
unsigned long *vmem = mbootinfo->framebuffer_addr;
|
unsigned long *vmem = mbootinfo->framebuffer_addr;
|
||||||
*vmem = 0xff00ff;
|
*vmem = 0xff00ff;
|
||||||
|
|
||||||
|
|
25
xtoa.c
25
xtoa.c
|
@ -49,3 +49,28 @@ char* ltoa(long value, int base) {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
char* ultoa(unsigned long value, int base) {
|
||||||
|
char* result;
|
||||||
|
|
||||||
|
// check that the base if valid
|
||||||
|
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
||||||
|
|
||||||
|
char* ptr = result, *ptr1 = result, tmp_char;
|
||||||
|
int tmp_value;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tmp_value = value;
|
||||||
|
value /= base;
|
||||||
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
||||||
|
} while ( value );
|
||||||
|
|
||||||
|
// Apply negative sign
|
||||||
|
//if (tmp_value < 0) *ptr++ = '-';
|
||||||
|
*ptr-- = '\0';
|
||||||
|
while(ptr1 < ptr) {
|
||||||
|
tmp_char = *ptr;
|
||||||
|
*ptr--= *ptr1;
|
||||||
|
*ptr1++ = tmp_char;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
1
xtoa.h
1
xtoa.h
|
@ -3,5 +3,6 @@
|
||||||
|
|
||||||
char* itoa(int value, int base);
|
char* itoa(int value, int base);
|
||||||
char* ltoa(long value, int base);
|
char* ltoa(long value, int base);
|
||||||
|
char* ultoa(unsigned long value, int base);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue