Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Number <-> ASCII Conversion

Status
Not open for further replies.
Here's a version without pointers,
Code:
void Mikes_itoa2(int Num,char* String){
char Start,End,Swap;
    Start=0;
    if(Num<0){                      //handle negative numbers
        Num=-Num;
        String[Start++]='-';
    }
    End=Start;                      //start of actual number
    do{                             //generate number backwards
        String[End++]=(Num%10)+0x30;
        Num/=10;
    }while(Num>0);
    String[End--]=0;                //string terminator
    while(End>Start){               //swap string around
        Swap=String[End];         
        String[End--]=String[Start];
        String[Start++]=Swap;
    }
}

Mike.
 
Pommie said:
I couldn't resist, I had to write one,

. . .snipped for brevity. . .

Note the dastardly xor swap at the end.:D

Mike.

Now that is a routine I like. :) Nice work.


Torben
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top