Question

5. Write a Complete C++ program which can produce the same result as shown below, i.e. convert numbers procedurally from deciBinar Deci mal Hexadeci Octal mal y 010 0 0 11 2 10 2 3/11 3 4 100 4. 4 5101 5 5 6110 6 6 7 111 7 7 81000 10 8 91001 11 9 101

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream> using namespace std; // function to convert decimal to binary void decToBinary(int n) { // array to store

void decToHexa(int n) { // char array to store hexadecimal number char hexadeciNum[100]; // counter for hexadecimal number ar

6 // function to convert decimal to octal > void decToOctal(int n) // array to store octal number int octalNum[100]; 2 3 1 //

int main() { cout << Decimal\t\tBinary\t\t\tOctal\tHexadecimal\n; for (int loop = 0; loop <= 15; ++loop ) { cout << dec « l

Input Decimal Binary Octal Hexadecimal 1 0 1 2 3 1 2 3 2 3 1 10 11 100 101 110 4 4 5 6 5 6 4 5 6 7 8 9 111 7 7 8 1000 1001 10

source code:


#include <iostream>

using namespace std;

// function to convert decimal to binary
void decToBinary(int n)
{
// array to store binary number
int binaryNum[32];
  
// counter for binary array
int i = 0;
while (n > 0) {
  
// storing remainder in binary array
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
  
// printing binary array in reverse order
for (int j = i - 1; j >= 0; j--)
cout << binaryNum[j];
}

// function to convert decimal to hexadecimal
void decToHexa(int n)
{
// char array to store hexadecimal number
char hexaDeciNum[100];
// counter for hexadecimal number array
int i = 0;
while(n!=0)
{ // temporary variable to store remainder
int temp = 0;
  
// storing remainder in temp variable.
temp = n % 16;
  
// check if temp < 10
if(temp < 10)
{
hexaDeciNum[i] = temp + 48;
i++; }
else
{
hexaDeciNum[i] = temp + 55;
i++; }
  
n = n/16; }
  
// printing hexadecimal number array in reverse order
for(int j=i-1; j>=0; j--)
cout << hexaDeciNum[j];
}
  
  
// function to convert decimal to octal
void decToOctal(int n)
{
  
// array to store octal number
int octalNum[100];
  
// counter for octal number array
int i = 0;
while (n != 0) {
  
// storing remainder in octal array
octalNum[i] = n % 8;
n = n / 8;
i++;
}
  
// printing octal number array in reverse order
for (int j = i - 1; j >= 0; j--)
cout << octalNum[j];
}   
  

int main()
{
cout << "Decimal\t\tBinary\t\t\tOctal\tHexadecimal\n";
for ( int loop = 0; loop <= 15; ++loop )
{
cout << dec << loop << "\t\t";
// Output binary number
decToBinary(loop);
cout<<"\t\t\t";
decToOctal(loop);
cout<<"\t";
decToHexa(loop);
cout<<"\n";

}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
5. Write a Complete C++ program which can produce the same result as shown below, i.e....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The place values for the eight binary digits used in IPv4 addressing are as follows: 128,...

    The place values for the eight binary digits used in IPv4 addressing are as follows: 128, 64, 32, 16, 8, 4, 2, 1. Expand this range to include an additional four bits. Do this by recording the place values for 211, 210, 29, and 28. 1111 Express the decimal value 2001 in binary by placing 1s in the binary positions requiring the addition of the corresponding place value. Place 0s in the binary positions where the corresponding place value should...

  • the w 2. This problem explores the use of a one-time pad version of t In...

    the w 2. This problem explores the use of a one-time pad version of t In this scheme, the key is a stream of random numbers between 0 and example, if the key is 3 19 5..., then the first letter of plaintext is encrypted with a shift of 3 letters, the second with a shift of 19 letters, the third with a shift of 5 letters, and so on. a. Encrypt the plaintext sendmoremoney with the key stream 9...

  • HW3: Problem 1: (first, study the example-1 in page-6) A computer uses 8-bit for FLP (1...

    HW3: Problem 1: (first, study the example-1 in page-6) A computer uses 8-bit for FLP (1 bit for sign, 4 bit for exponent with excess-7 rep. (see table below), rest for magnitude). Assume 0000 and 1111 in exponent field are reserved for denormalization. 6 Decimal 0 Unsigned 0000 Excess-7 Reserved used as -6 in unnormalized 1 0001 -6 2 0010 -5 3 0011 -4 4 0100 -3 5 0101 -2 0110 -1 7 0111 0 9 Decimal 8 Unsigned 1000...

  • Arduino. DEC HEX BIN(4-bits) Introducing ARDUINO 0 0 0000 1 1 0001 2 2 0010 3...

    Arduino. DEC HEX BIN(4-bits) Introducing ARDUINO 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 How many 1/0 of Port-D? How many usable 1/0 of Port-D, if Serial-Communication is in-used? What is the Arduino's pin assignment of ATMEL's PC5, PB3, & PD1*? What is the ATMEL's pin assignment of Arduino's D13*, D1, & D19? To complete the table about Number System Conversion (shown your step) 6 6 0110 7 7 0111...

  • I'm working on a java program where I'm supposed to convert 4 bit binary into decimal....

    I'm working on a java program where I'm supposed to convert 4 bit binary into decimal. I went with if statements and tried to use an else to print out an error message if the user enters a number that isn't a binary number but it prints no matter what. (so, it prints that it's a vowel and that it's not a vowel) 1 import java.util.Scanner; 2 3 public class HomeworkTwoQ2 4 { 5 6 public static void main(String[] args)...

  • Preparation (Pre-lab) Before coming to the first lab session, complete the following tasks: Generate a truth...

    Preparation (Pre-lab) Before coming to the first lab session, complete the following tasks: Generate a truth table showing inputs vs outputs for the following circuit blocks in Part I: Comparator, Circuit A, and Circuit B. o Use the truth tables to produce minimized SOP (sum of products) for the Comparator, Circuit A and Circuit B. Part I - Simple Binary to BCD Conversion Design Specifications You are to design a circuit that converts a four-bit binary number V[3..0] = V[3]...

  • I need little help with C language. I need to pass what I get from HexToBin(char*...

    I need little help with C language. I need to pass what I get from HexToBin(char* hexdec) into char* input so that what I got there it should pass it as string array parametr. Example: Enter IEEE-Hex: 40200000 Equivalent Binary value is : 01000000001000000000000000000000 Decimal Number: 2.5 #include <stdio.h> void HexToBin(char* hexdec) {    long int i = 0;    while (hexdec[i]) {        switch (hexdec[i]) {        case '0':            printf("0000");            break;...

  • Java: can also use “if else” statements Write a program that can convert an integer between...

    Java: can also use “if else” statements Write a program that can convert an integer between 0 and 15 into hex number (including 0 and 15). The user enters an integer from the console and the program displays the corresponding hex number. If the user enters an integer out of range, the program displays a warning message about the invalid input. Table. Conversion between Decimal and Hexadecimal Decimal Hexadecimal 0 0 1 1 2 2 3 3 4 4 5...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. DON'T use Function concept or any other concept except while loop,if-else. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT