#include <iostream>
#include <string>
#include <sstream>
#include "hex.h"
//constructor
Hex::~Hex() //destructor
{
}
int Hex::toInt()
{
int num;
std::stringstream toBeConverted(hexNumber);
toBeConverted >> std::hex >> num;
return num;
}
std::string Hex::toBin()
{
std::string binaryNum;
std::transform(hexNumber.begin(),hexNumber.end(),h exNumber.begin(),tolower);
for (int i = 0; i <= hexNumber.length() ; i++)
{
if (hexNumber.substr(i,1) == "0")
binaryNum += "0";
if (hexNumber.substr(i,1) == "1")
binaryNum += "1";
if (hexNumber.substr(i,1) == "2")
binaryNum += "10";
if (hexNumber.substr(i,1) == "3")
binaryNum += "11";
if (hexNumber.substr(i,1) == "4")
binaryNum += "100";
if (hexNumber.substr(i,1) == "5")
binaryNum += "101";
if (hexNumber.substr(i,1) == "6")
binaryNum += "110";
if (hexNumber.substr(i,1) == "7")
binaryNum += "111";
if (hexNumber.substr(i,1) == "8")
binaryNum += "1000";
if (hexNumber.substr(i,1) == "9")
binaryNum += "1001";
if (hexNumber.substr(i,1) == "a")
binaryNum += "1010";
if (hexNumber.substr(i,1) == "b")
binaryNum += "1011";
if (hexNumber.substr(i,1) == "c")
binaryNum += "1100";
if (hexNumber.substr(i,1) == "d")
binaryNum += "1101";
if (hexNumber.substr(i,1) == "e")
binaryNum += "1110";
if (hexNumber.substr(i,1) == "f")
binaryNum += "1111";
}
return binaryNum;
}
std::string Hex::toHex()
{
std::stringstream hexNum;
hexNum << std::hex << decNumber;
hexNum >> hexNumber;
return hexNumber;
}
i need a converter that will accept a input of a binary then it will convert it to hexa.. if you have a better way or code pls post it here i really need your help guys please... T_T.. im really noob at programming i wanna disect this program so i can defend it to my prof.. thanks in future be patient waiting ..