0
#include "stdafx.h"
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>

using namespace std;


class hextobin
{
private:

public:
    void convh_b(string);
};

// function convh_b 
void hextobin::convh_b(string x)
{
    for(int i = 0; i<6; i++)
    {
        switch(x[i])
        {
        case '0': cout << "0000"; break;
        case '1' :cout << "0001"; break;
        case '2': cout << "0010"; break;
        case '3': cout << "0011"; break;
        case '4': cout << "0100"; break;
        case '5': cout << "0101"; break;
        case '6': cout << "0110"; break;
        case '7': cout << "0111"; break;
        case '8': cout << "1000"; break;
        case '9': cout << "1001"; break;
        case 'A': cout << "1010"; break;
        case 'B': cout << "1011"; break;
        case 'C': cout << "1100"; break;
        case 'D': cout << "1101"; break;
        case 'E': cout << "1110"; break;
        case 'F': cout << "1111"; break;
        }
    }

    cout << endl;
}

void main()
{
    hextobin p;
    string  l1;
    ifstream myfile("assembly.txt");

    if(myfile.is_open())
    {
        while(!myfile.eof())
        {
            getline(myfile, l1);
            cout << l1 << endl;
            p.convh_b(l1);
        }

        myfile.close();
    }
    else
        cout << "unable";
}

my code reads hex numbers from file then convert them to binary except the last digit of the first line ??

Example:

FF01
B521

Output:

111111110000    // here 1 hexa not converted to 0001 ?? 
1011010100100001 
LogicStuff
  • 19,397
  • 6
  • 54
  • 74
Dua'a Al-helou
  • 29
  • 1
  • 1
  • 3

0 Answers0