//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / OVOPS++
//
//File: tools.cpp
//
//Version: $Revision: 1.2 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/11/20 13:59:53 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Timo Pärnänen
//	Jari Koskivuori
//
//Description:
//      See corresponding header file.
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History: 

#include "tools.h"


string pfTools :: intToString(const pfUlong number_)
{
    string result;
    pfUlong number = number_;
    
    while (number > 0)
    {
        result = (char)((number % 10) + 48) + result;
        number /= 10;
    }
    return result;
}

//
// Method: hexToDec
//
// Description:
//     Converts an ascii hexadesimal number into binary desimal
//

int pfTools :: hexToDec(int hexnum_)
{
    int result = 0;
    if (isdigit(hexnum_) != 0)
    {
        result = hexnum_-'0';
    }
    else
    {
        hexnum_ = toupper(hexnum_);
        if ((hexnum_ >= 'A') && (hexnum_ <= 'F'))
        {
            result = 10 + hexnum_ - 'A';
        }
    }
    return result;
}

//
// Method: decToHex
//
// Description:
//     Converts a binary desimal number into ascii hexadesimal
//

int pfTools :: decToHex(int decnum_)
{
    int result = 0;
    if ((decnum_ >= 0) && (decnum_ <= 9))
    {
        result = '0' + decnum_;
    }
    else if ((decnum_ >= 10) && (decnum_ <= 15))
    {
        result = 'A' + decnum_ - 10;
    }

    return result;
}

