# Forum: µC & Digital Electronics Convert Unsigned 8 bit integer to a string ?

Rate this post
 0 ▲ useful ▼ not useful
How shall i convert a unsigned 8 bit integer to a string without using
any libaries.... Only self written functions.

Rate this post
 0 ▲ useful ▼ not useful
If you use C:
  unsigned char number_txt, hundred=0, ten=0; while(1) { if(number>=100) { number=number-100; hundred++; } else break; } while(1) { if(number>=10) { number=number-10; ten++; } else break; } number_txt=hundred+'0'; number_txt=ten+'0'; number_txt=number+'0'; number_txt=0x00;

: Edited by User

Rate this post
 0 ▲ useful ▼ not useful
Why this construct with while(1)/if?

This is simpler:
  unsigned char number_txt, hundred=0, ten=0; while (number >= 100) { number = number-100; hundred++; } while (number >= 10) { number = number-10; ten++; } number_txt = hundred+'0'; number_txt = ten+'0'; number_txt = number+'0'; number_txt = 0; 

or still shorter:

  unsigned char number_txt, hundred=0, ten=0; while (number >= 100) { number -= 100; hundred++; } while (number >= 10) { number -= 10; ten++; } number_txt = hundred+'0'; number_txt = ten+'0'; number_txt = number+'0'; number_txt = 0; 

Rate this post
 0 ▲ useful ▼ not useful
I am trying to read it to an LCD display, but I am getting random
character on the display...

Rate this post
 0 ▲ useful ▼ not useful
When i number = 100, is the character i get on my LCD

11111
11010
11111
11111
11111
11111
11111
11111

Rate this post
 0 ▲ useful ▼ not useful
And what characters are on your lcd if you write out the string "100"
direct?

Rate this post
 0 ▲ useful ▼ not useful
when i write 100 the char.  ] and
1111
1110
1100
1111
1101
1111
1111
1110

and if I write "100", 100 appears on the LCD.

oh.. i might have found the solution.. is it possible to get beyond the
limitation of the size of number..

: Edited by User

• $formula (LaTeX syntax)$