1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Butoxors [25]
4 years ago
11

Write a program that reads a 4-bit binary number from the keyboard as a string and then converts it into decimal. For example, i

f the input is 1100, the output should be 12. (Hint: Break the string into substrings and then convert each substring to a value for a single bit. If the bits are b0, b1, b2, and b3, the decimal equivalent is 8b0+ 4b1+ 2b2+ b3.)
Computers and Technology
1 answer:
adell [148]4 years ago
7 0

Answer:

import java.util.Scanner;

public class ss11{

       public static void main (String[]args) {

             Scanner keyboard = new Scanner (System.in)

             String a1, a2, a3, a4, a5;

              int i1, i2, i3, i4, i5;

              System.out.println("Enter a four bit binary number:");

               a1= keyboard.next();

               a2= a1.substring(0,1);

               a3= a1.substring(1,2);

               a4= a1.substring(2,3);

               a5= a1.substring(3,4);

                i1 = Integer.parseInt(a2);

                i2 = Integer.parseInt(a3);

                i3 = Integer.parseInt(a4);

                i4 = Integer.parseInt(a5);

                i1= i1 * 8;

                i2= i1 * 4;

                i3= i1 * 2;

                i4= i1 * 1;

                i5= i1+i2+i3+i4;

                System.out.println("The converted decimal number is: +i5);

}

}

Explanation:

You might be interested in
How to add bullet points in google slides??
Anettt [7]
<span>Open a document or presentation.Add or select a text box.<span>On the toolbar, click Bulleted list  or Numbered list .<span>Note: If you don't see the option, click More.</span></span>To change the style of the bullets or numbers, click the dropdown arrow next to the icons in the toolbar</span>
6 0
4 years ago
Read 2 more answers
When should an individual consider entering parenthood?
-BARSIC- [3]
  In my opinion, after marriage. And during the time you're married, be sure you are going to stay with that person a long time because divorces can cause mental health issues towards the child. And if your loved one is abusive, an alcoholic, etc. then you should get out that relationship immediately before having children. Therefore, your children will have a happy, healthy, life. 
5 0
3 years ago
Write down a pair of integers whose sum is​ 0
Tems11 [23]

Answer:

-1 ans +2 are the pair of integers whose sum is 0.

3 0
3 years ago
Movie recommendations? I’m in middle school so nothing nasty bro and I don’t really like horror movies so none of those either
lbvjy [14]

Answer:

watch happy gilmore

Explanation:

5 0
3 years ago
Read 2 more answers
Study the editorial cartoon Participation in Youth Sports Down by Dan Landgren Jr.
Sergeu [11.5K]

Answer:

What is the coordinates of points B in the diagram

Explanation:

D

8 0
4 years ago
Read 2 more answers
Other questions:
  • The binary search algorithm ________. will have a maximum number of comparisons equal to the number of elements in the array wil
    7·1 answer
  • What is a possible style of formatting your company could prefer?
    14·2 answers
  • Why people needs soft skills in the era of high technology.
    13·1 answer
  • Protected base class members cannot be accessed by: a.friends of the base class.
    6·1 answer
  • is family mobile and boost mobile the same? if not whats the difference? (btw this is a random question)
    12·2 answers
  • For a wire with a circular cross section and a diameter = 3.00mm calculate the following: (m means meter. mm means millimeter. c
    5·1 answer
  • Time complexity: Be sure to show your work. Suppose that a particular algorithm has time complexity T (n) = 10 ∗ 2n, and that ex
    7·1 answer
  • Explain with a few sentences and using the terms sequencing, selections and loops how they
    9·1 answer
  • Why stress testing is needed?​
    14·2 answers
  • Anil needs to show the overlap of people who live in a certain neighborhood in his city and who support a specific political can
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!