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.

Mike.

Now that is a routine I like. Nice work.


Torben
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…