Answer to Question #195925 in C++ for zain ul abdeen

Question #195925
Question1 - write a program, do rough work on the same program.
a) Write your university registration number. Underline the last three digits of your number.
b) Consider the last three digits of your number a decimal number, convert it to a binary number.
c) Add a binary 1 to the answer you got from part b.
d) Convert the answer of part c, to hexadecimal number.
e) Convert the answer of part c, to decimal number.
f) Consider the last three digits of your number a hexadecimal number, convert it to a binary number.
g) Convert 1100111110100000 binary to hexadecimal number.
For example registration number last three digit 156.
1
Expert's answer
2021-05-20T14:06:08-0400
#include <iostream>
#include <conio.h>
#include <string>


using namespace std;


int dec2bin(int num) {
	int bin = 0, k = 1;


	while (num) {
		bin += (num % 2) * k;
		k *= 10;
		num /= 2;
	}
	return bin;
}
int Bin2Dec(int num) {
	int result = 0;
	for (int i = 1; num; num /= 10, i *= 2)
	{
		result += i * (num % 10);
	}
	return result;
}


int main() {
	int num;
	cout << "Enter university registration number";
	cin >> num;
	string str = to_string(num);
	string st = "";
	for (int i = str.size() - 3; i < str.size(); ++i)
		st += str[i];
	int numb = stoi(st);
	int du = dec2bin(numb);
	string st2 = to_string(du) + "1";
	int nu = stoi(st2);
	int num2 = Bin2Dec(nu);
	cout << hex << num2 << endl;
	_getch();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog