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

 Author: John Mayer (215) Posted on: 2014-04-25 01:42

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.

 Author: Max H. (hartl192) Posted on: 2014-04-25 01:59

Rate this post
 0 ▲ useful ▼ not useful
If you use C:
  unsigned char number_txt[4], 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[0]=hundred+'0'; number_txt[1]=ten+'0'; number_txt[2]=number+'0'; number_txt[3]=0x00;

: Edited by User
 Author: T_T (Guest) Posted on: 2014-04-25 08:27

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

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

or still shorter:

  unsigned char number_txt[4], hundred=0, ten=0; while (number >= 100) { number -= 100; hundred++; } while (number >= 10) { number -= 10; ten++; } number_txt[0] = hundred+'0'; number_txt[1] = ten+'0'; number_txt[2] = number+'0'; number_txt[3] = 0; 

 Author: John Mayer (215) Posted on: 2014-04-25 10:11

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...

 Author: John Mayer (215) Posted on: 2014-04-25 11:13

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

 Author: T_T (Guest) Posted on: 2014-04-25 21:50

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

 Author: John Mayer (215) Posted on: 2014-04-25 21:53

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)$