hat creates an array data of size 8, representing a binary number of 8 bits. The user must fill/enter the elements of this array only by inputting 0 or 1. If the user enters any different number, the program must display “Invalid data” message. If all entered digits are valid binary digits, the program must calculate and output the special decimal number represented by this binary n

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 22PE
icon
Related questions
Question
Write a Java program that creates an array data of size 8, representing a binary number of 8 bits. The user must fill/enter the elements of this array only by inputting 0 or 1. If the user enters any different number, the program must display “Invalid data” message. If all entered digits are valid binary digits, the program must calculate and output the special decimal number represented by this binary number as shown in the below example: If the array data is 1 | 0 | 1 1 0 0 0 0 Result=1X2°+ 0X2'+ 1X2%+ 1X2'+ 0X2'+ 0X2°+ 0X2°+ 0X2 Result = 1 L3 0 + 4 + 8 + 0 + 0 + 0 + 0 = 13 Then the result is calculated by multiplying the value of the data array at each index with the result of 21 then adding all the answers. (shown in the above example) Sample runl: Enter the digits consisting of (0s or 1s): 2 5413257 Invalid data Sample run2: Enter the digits consisting of (0s or 1s): 1 111000 2 Invalid data Sample run3: Enter the digits consisting of (0s or 1s): 11110000 The number in decimal is 15 Sample rund: Enter the digits consisting of (0s or 1s): 1 0110000 The number in decimal is 13
Write a Java program that creates an array data of size 8, representing a binary number of 8 bits.
The user must fill/enter the elements of this array only by inputting 0 or 1. If the user enters any different
number, the program must display "Invalid data" message.
If all entered digits are valid binary digits, the program must calculate and output the special decimal number
represented by this binary number as shown in the below example:
If the array data is
1
1
1
O X 24 +
0 X2' +
1 X 22 +
0 + 4
0 X 2° +
0 +
1 X 2' +
0 X27
0 x 25 +
0 +
Result = 1 X 2°+
Result =
1
8.
+ 0
13
Then the result is calculated by multiplying the value of the data array at each index with the result of 2index
then adding all the answers. (shown in the above example)
Sample run1:
Enter the digits consisting of (0s or 1s): 2 5 4 1 3 2 5 7
Invalid data
Sample run2:
Enter the digits consisting of (0s or 1s): 1 1 1 1 0 0 0 2
Invalid data
Sample run3:
Enter the digits consisting of (0s or 1s): 1 1 1 1 0 0 0 0
The number in decimal is 15
Sample run4:
Enter the digits consisting of (0s or 1s): 1 0 1 1 0 0 0 0
The number in decimal is 13
Transcribed Image Text:Write a Java program that creates an array data of size 8, representing a binary number of 8 bits. The user must fill/enter the elements of this array only by inputting 0 or 1. If the user enters any different number, the program must display "Invalid data" message. If all entered digits are valid binary digits, the program must calculate and output the special decimal number represented by this binary number as shown in the below example: If the array data is 1 1 1 O X 24 + 0 X2' + 1 X 22 + 0 + 4 0 X 2° + 0 + 1 X 2' + 0 X27 0 x 25 + 0 + Result = 1 X 2°+ Result = 1 8. + 0 13 Then the result is calculated by multiplying the value of the data array at each index with the result of 2index then adding all the answers. (shown in the above example) Sample run1: Enter the digits consisting of (0s or 1s): 2 5 4 1 3 2 5 7 Invalid data Sample run2: Enter the digits consisting of (0s or 1s): 1 1 1 1 0 0 0 2 Invalid data Sample run3: Enter the digits consisting of (0s or 1s): 1 1 1 1 0 0 0 0 The number in decimal is 15 Sample run4: Enter the digits consisting of (0s or 1s): 1 0 1 1 0 0 0 0 The number in decimal is 13
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Arrays
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning