Question

In: Computer Science

Convert a list of decimal numbers into their binary and hexadecimal equivalents Add the elements of...

  1. Convert a list of decimal numbers into their binary and hexadecimal equivalents
  2. Add the elements of each of these lists to generate a total sum
  3. Print the lists, and the total sum of each value

C++ contains some built-in functions (such as itoa and std::hex) which make this assignment trivial. You may NOT use these in your programs. You code must perform the conversion through your own algorithm.

The input values are:


5

9

24

2

39

83

60

8

11

10

6

18

31

27

Solutions

Expert Solution

#include<iostream>
using namespace std;
//method to convert to binary
int toBinary(int n)
{
   if(n==0)
   return 0;
   return toBinary(n/2)*10 + n%2;
}
//method to convert number to hexadecimal
string toHex(int n)
{
   char c[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
   if(n==0)
   return "";
   return toHex(n/16)+ ""+c[n%16];
}
int main()
{
   int n;
   cout<<"Enter how many number u want to enter:";
   cin>>n;
   cout<<"Enter numbers:";
   int m,i=1;
   while(i<=n)
   {
       cout<<i<<":";
       cin>>m;
       cout<<"Binary :"<<toBinary(m)<<endl;  
       cout<<"Hexadecimal :"<<toHex(m)<<endl;
       i++;
   }
  
   return 0;
}

output:

Enter how many number u want to enter:14
Enter numbers:1:5
Binary :101
Hexadecimal :5
2:9
Binary :1001
Hexadecimal :9
3:24
Binary :11000
Hexadecimal :18
4:2
Binary :10
Hexadecimal :2
5:39
Binary :100111
Hexadecimal :27
6:83
Binary :1010011
Hexadecimal :53
7:60
Binary :111100
Hexadecimal :3C
8:8
Binary :1000
Hexadecimal :8
9:11
Binary :1011
Hexadecimal :B
10:10
Binary :1010
Hexadecimal :A
11:6
Binary :110
Hexadecimal :6
12:18
Binary :10010
Hexadecimal :12
13:31
Binary :11111
Hexadecimal :1F
14:27
Binary :11011
Hexadecimal :1B


Process exited normally.
Press any key to continue . . .


Related Solutions

Convert the following binary values to hexadecimal and decimal (1 pt each) Write Hex Numbers as...
Convert the following binary values to hexadecimal and decimal (1 pt each) Write Hex Numbers as 0x##(ex 0x0A, 0xFF) Binary Hexadecimal Decimal 0001-1011 0x 0000-1000 0000-0100 0000-1001 0001-1111 1001-1001 0111-1010 1100-0010 1110-0101 1000-1010 0011-0100 0001-1001 0100-0011 1111-1111 1110-0111 0001-0010 0100-1000 0100-1110 1001-0001 0110-1100 Name: Convert the following hexadecimal values to binary and decimal Write binary numbers as 0000-0000 Hexadecimal Binary Decimal 0xf1 0xac 0x56 0x6c 0x32 0x30 0x05 0x28 0xf0 0x07 0x42 0xb9 0x6d 0x2f 0x71 0x0e 0x2d 0xfb 0xba...
Convert from hexadecimal to binary to decimal (PLEASE SHOW WORK) 1. B2 - binary: - decimal:...
Convert from hexadecimal to binary to decimal (PLEASE SHOW WORK) 1. B2 - binary: - decimal: 2. 37 - binary: - decimal: 3. 0A -binary: - decimal: 4. 11 - binary: - decimal:
Convert from binary to decimal to hexadecimal (PLEASE SHOW ALL WORK) a. 1010 1011 - decimal:...
Convert from binary to decimal to hexadecimal (PLEASE SHOW ALL WORK) a. 1010 1011 - decimal: - hexadecimal b. 0011 0001 - decimal: - hexadecimal: c. 1110 0111 - decimal: - hexadecimal: d. 1111 1111 - decimal: - hexadecimal:
Convert the following decimal numbers to 16-bit 2’s complement binary. Display your result in hexadecimal. a.3030...
Convert the following decimal numbers to 16-bit 2’s complement binary. Display your result in hexadecimal. a.3030 b.404 c.5050 d.-5050 e.-20000 Show work with steps
i need to convert decimal to twos complement binary and then add the binary digits but...
i need to convert decimal to twos complement binary and then add the binary digits but I am unable to do it. I am only allowed to use string, can anyone help me out please. i need the code urgently. #include #include #include #include using namespace std; string reverse(string s) { string x = ""; for (long i = s.length() - 1; i >= 0; i--) { x += s[i]; } return x; } string twosComplementStringsAddition(string A, string B) {...
Convert 110.7510 to binary ______ and hexadecimal ______. Show the answer in both binary and hexadecimal....
Convert 110.7510 to binary ______ and hexadecimal ______. Show the answer in both binary and hexadecimal. There are ____________ kilobytes in a megabyte. Convert -13210 to a 16-bit 2’s complement in binary ____________ and hexadecimal ______________.
write a python code to Determine the binary and decimal representations of the following hexadecimal numbers....
write a python code to Determine the binary and decimal representations of the following hexadecimal numbers. Store answers in the appropriate variables in the .py file. (a) 0xfca1 (b) 0xc4d8
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are not allowed to use library functions for conversion. The output should look exactly as follows: DECIMAL      BINARY                     HEXDECIMAL                      BCD 0                      0000 0000                   00                                            0000 0000 0000 1                      0000 0001                   01                                            0000 0000 0001 2                      0000 0010                   02                                            0000 0000 0010 .                       .                                   .                                               . .                       .                                   .                                               . 255                  1111 1111                   FF                                            0010 0101 0101
Convert these numbers from Decimal to Binary 111: 66: 252 11 20 Convert these numbers from...
Convert these numbers from Decimal to Binary 111: 66: 252 11 20 Convert these numbers from Binary to Decimal 00110110 11111000 00000111 10101010 What is the Default Subnet mask of Class A IPV4 What is the Default Subnet mask of Class B IPV4 What is the Default Subnet mask of Class C IPV4 What is the CIDR notation or / short handwriting of Subnet masks: Class A: /?. Explain the reason Class B: /? Explain the reason Class C: /?...
1. Convert to binary and hexadecimal (PLEASE SHOW WORK) a. 35 - binary: - hexadecimal: b....
1. Convert to binary and hexadecimal (PLEASE SHOW WORK) a. 35 - binary: - hexadecimal: b. 85 - binary: - hexadecimal: c. 128 - binary: - hexadecimal: d. 4563 - binary: - hexadecimal:
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT