0% found this document useful (0 votes)
9 views4 pages

2023 Ce 52

This document is an assignment for the course CMPE-223, submitted by Minhaj Khalid to Dr. Asim on February 25, 2025. It includes C++ code for base conversion functions, such as converting decimal to hexadecimal and converting numbers between different bases. The code demonstrates the implementation of these conversions using standard libraries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

2023 Ce 52

This document is an assignment for the course CMPE-223, submitted by Minhaj Khalid to Dr. Asim on February 25, 2025. It includes C++ code for base conversion functions, such as converting decimal to hexadecimal and converting numbers between different bases. The code demonstrates the implementation of these conversions using standard libraries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT

Course Title:
CMPE-223
Computer Organization

Semester:
FOURTH
Spring 2025

Submitted by:
2023-CE-52

Minhaj Khalid

Submitted to:
Dr. Asim

Date of Submission:
Feb 25, 2025

__________________________________________________________________
Department of Computer Engineering
University of Engineering and Technology, Lahore
Base Conversion Code

#include <iostream>

#include <string>

#include <cmath>

#include <sstream>

using namespace std;

string Decimal_To_Hex(int number) {

stringstream ss;

ss << hex << number;

return ss.str();

int ToDecimal(string num, int base){

int decimal=0;

int power=num.length()-1;

for (int i=0; i<num.length(); i++){

int a=num[i]-'0';

decimal+=pow(base,power)*a;

power--;
}

return decimal;

int Decimal_To_Base(int num, int base){

string result="";

while (num>0){

int r=num%base;

string str=to_string(r);

result+=str;

num/=base;

int i=0;

int j=result.length()-1;

while (i<=j){

swap(result[i],result[j]);

i++;

j--;

int final_result=stoi(result);

return final_result;

}
int main(){

cout << Decimal_To_Hex(10) ;

You might also like