17.33 Lab: Vectors: Binary to decimal conversion A binary number's digits are only 0's and 1's, which each digit's weight being an increasing power of 2. Ex: 110 is 1*22 + 1*21 + 0*20 = 1*4 + 1*2 + 0*1 = 4 + 2 + 0 = 6. A user enters an 8-bit binary number as 1's and 0's separated by spaces. Then compute and output the decimal equivalent. Ex: For input 0 0 0 1 1 1 1 1, the output is: 31 (16 + 8 + 4 + 2 + 1) Hints: Store the bits in reverse, so that the rightmost bit is in element 0. Write a for loop to read the input bits into a vector. Then write a second for loop to compute the decimal equivalent. To compute the decimal equivalent, loop through the elements, multiplying each by a weight, and adding to a sum. Use a variable to hold the weight. Start the weight at 1, and then multiply the weight by 2 at the end of each iteration.   The assignment is to find main.cpp In C++ please. Very urgent. Your help is very much appreciated.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

17.33 Lab: Vectors: Binary to decimal conversion

A binary number's digits are only 0's and 1's, which each digit's weight being an increasing power of 2. Ex: 110 is 1*22 + 1*21 + 0*20 = 1*4 + 1*2 + 0*1 = 4 + 2 + 0 = 6. A user enters an 8-bit binary number as 1's and 0's separated by spaces. Then compute and output the decimal equivalent. Ex: For input 0 0 0 1 1 1 1 1, the output is:

31

(16 + 8 + 4 + 2 + 1)

Hints:

  • Store the bits in reverse, so that the rightmost bit is in element 0.

  • Write a for loop to read the input bits into a vector. Then write a second for loop to compute the decimal equivalent.

  • To compute the decimal equivalent, loop through the elements, multiplying each by a weight, and adding to a sum.

  • Use a variable to hold the weight. Start the weight at 1, and then multiply the weight by 2 at the end of each iteration.

 

The assignment is to find main.cpp

In C++ please. Very urgent. Your help is very much appreciated.

17.33 Lab: Vectors: Binary to decimal conversion
A binary number's digits are only O's and 1's, which each digit's weight being an increasing power of 2. Ex: 110 is 1*2² + 1*2¹ + 0*20 = 1*4 +
1*2 + 0*1 = 4 + 2 + 0 = 6. A user enters an 8-bit binary number as 1's and O's separated by spaces. Then compute and output the decimal
equivalent. Ex: For input 0 0 0 1 1 1 1 1, the output is:
31
(16+8+4+2+1)
Hints:
• Store the bits in reverse, so that the rightmost bit is in element 0.
• Write a for loop to read the input bits into a vector. Then write a second for loop to compute the decimal equivalent.
• To compute the decimal equivalent, loop through the elements, multiplying each by a weight, and adding to a sum.
• Use a variable to hold the weight. Start the weight at 1, and then multiply the weight by 2 at the end of each iteration.
407520.2514600.ax3zav7
Transcribed Image Text:17.33 Lab: Vectors: Binary to decimal conversion A binary number's digits are only O's and 1's, which each digit's weight being an increasing power of 2. Ex: 110 is 1*2² + 1*2¹ + 0*20 = 1*4 + 1*2 + 0*1 = 4 + 2 + 0 = 6. A user enters an 8-bit binary number as 1's and O's separated by spaces. Then compute and output the decimal equivalent. Ex: For input 0 0 0 1 1 1 1 1, the output is: 31 (16+8+4+2+1) Hints: • Store the bits in reverse, so that the rightmost bit is in element 0. • Write a for loop to read the input bits into a vector. Then write a second for loop to compute the decimal equivalent. • To compute the decimal equivalent, loop through the elements, multiplying each by a weight, and adding to a sum. • Use a variable to hold the weight. Start the weight at 1, and then multiply the weight by 2 at the end of each iteration. 407520.2514600.ax3zav7
LAB
ACTIVITY
17.33.1: Lab: Vectors: Binary to decimal conversion
1 #include <iostream>
2 #include <vector>
3 using namespace std;
4
5 int main() {
6
7 vector<int> binaryNum(8);
8
9
10
11
12
13
14
15
16
17
18
19
20 }
int digitWeight;
int decimal Sum;
int i;
// Get user's binary number. Store leftmost bit in element 7, rightmost in 0.
// Hint: for (...) {
cin >> binaryNum. at(i);
}
/* Type your code here. */
main.cpp
return 0;
0/3
Load default template...
Transcribed Image Text:LAB ACTIVITY 17.33.1: Lab: Vectors: Binary to decimal conversion 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 5 int main() { 6 7 vector<int> binaryNum(8); 8 9 10 11 12 13 14 15 16 17 18 19 20 } int digitWeight; int decimal Sum; int i; // Get user's binary number. Store leftmost bit in element 7, rightmost in 0. // Hint: for (...) { cin >> binaryNum. at(i); } /* Type your code here. */ main.cpp return 0; 0/3 Load default template...
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Parallel Processing
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education