/**************************************************************************
 * File:conversions.c
 *
 * Functions holding basing number to string functions
 *
 * File Creation           : 4/20/2006
 *
 * author : Jyotsna Chitri
 * $Author: B04496 $
 *
 * Copyright Freescale Semiconductor Inc
 * 2006 All Rights Reserved
 *
 * Notes :
 * <RELEVANT information only - leave blank if none>
 *
 *
 * Revision History :
 *  $Date: 2006/09/13 20:16:20 $
 *
 *
 *************************************************************************/

/*********************************************************************************
   Function Name : numb_to_str()
   
   Description:To Convert a number to a string
   
   Inputs: Number to be converted, string buffer
   
   Outputs:Length of the converted string
   
 **********************************************************************************/

int num_to_str(long int number, unsigned char result[])
{

  int cnt = 0;
  int i = 0;
  int index =0;
  int digit =0;

  unsigned char temp[10];

  if(number ==0) {

    result[index] = '0';                /*Ascii 48 */
    index++;
  }
  else
  {
    if(number < 0)                      /*negative sign*/
    {
      result[index] = '-';              /*Ascii 45 */
      index++;
      number = (number * (-1));
    }

    while (number!=0)
    {
      digit =number%10;                 /*get the reminder*/

      temp[cnt]=(char)(digit+48);       /*convert to ascii character*/
      number = number/10;               /*remove current ones digit*/
      cnt++;                            /*length of number*/
    }

    /* Arrange the numbers in correct order */

    for(i=cnt-1;i>=0;i--)
    {
      result[index]=temp[i];            /*reorder string correctly*/
      index++;
    }
  }
  result[index]='\0';                   /*Add Null at the end of string*/
  return index;
}
