Need help converting from hex to binary any help is very appreciated!!
#include <string>
#include <iostream>
class Hex
{
private: //constructor
std::string hexNumber;
int decNumber;
public:
Hex(std::string hNum): hexNumber(hNum)
{}
Hex(int dNum): decNumber(dNum)
{}
~Hex();
int toInt();
std::string toBin();
std::string toHex();
};
it keeps saying i need to put a semicolon before the period on line 23 not too sure exactly where its talking about or maybe i did something wrong.
#include <iostream>
#include <string>
#include <sstream>
#include "hex.h"
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::string hexNumber.begin(),hexNumber.end(),hexNumber.begin(),tolower;
for (int i = 0; i = hexNumber.length() ; i++)
{
if (hexNumber.substr(i,1) == "0")
binaryNum += "0000";
if (hexNumber.substr(i,1) == "1")
binaryNum += "0001";
if (hexNumber.substr(i,1) == "2")
binaryNum += "0010";
if (hexNumber.substr(i,1) == "3")
binaryNum += "0011";
if (hexNumber.substr(i,1) == "4")
binaryNum += "0100";
if (hexNumber.substr(i,1) == "5")
binaryNum += "0101";
if (hexNumber.substr(i,1) == "6")
binaryNum += "0110";
if (hexNumber.substr(i,1) == "7")
binaryNum += "0111";
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;
}