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]
3 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]3 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
Write the definitions for three function named max. Each receives two parameters, of the same type, and returns the larger of th
GenaCL600 [577]

Answer:

The method definition to this question can be given as:

Method definition:

double max(double x, double y)  //define method with double parameter  

{

if (x>=y)    //check condition.

return x;  //return value

else

return y;     //return value

}

double max(int x, int y)    //define method with integer parameter

{

if (x>=y)    //check condition

return x;    //return value

else

return y;  //return value

}

double max(char x, char y)   //define method with char parameter

{

if (x>=y)    //check condition

return x;    //return value

else

return y;    //return value

}

Explanation:

The above method definition can be described as below:

  • In the first method definition first, we define a method that is "max()". In this method we pass two variables as a parameter that is "x and y" and the datatype of this is double. Then we use a conditional statement. In the if block we check if variable x is greater then equal to y then it will return x else it will return y.  
  • In the second method definition, we define a method that is same as the first method name but in this method, we pass two integer variable that is "x and y". Then we use a conditional statement. In the if block we check if variable x is greater then equal to y then it will return x else it will return y.
  • In the third method definition, we define a method that is same as the first and second method name but in this method, we pass two char variable that is "x and y". Then we use a conditional statement. In the if block we check if variable x is greater then equal to y then it will return x else it will return y.
8 0
3 years ago
Find the equation of a line which has 10 points the following two coordinates: (4, 0) and (3, 4)​
alex41 [277]

Answer:

The equation of the line is y = -4·x + 16

10 points on the line include;

(0, 16), (1, 12), (2, 8), (3, 4), (4, 0), (5, -4), (6, -8), (7, 12), (8, -16), (9, -20), and (10, -24)

Explanation:

The given points through which the line passes are;

(4, 0) and (3, 4)

The slope, 'm', of the line is given as follows;

Slope, \, m =\dfrac{y_{2}-y_{1}}{x_{2}-x_{1}}

Therefore, the slope of the line is (4 - 0)/(3 - 4) = -4

In point and slope form we can get;

\dfrac{y-0}{x-4} = -4

The equation of the line in point and slope form is therefore;

y = -4·(x - 4) = -4·x + 16

The equation of the line in slope and intercept form is

y = -4·x + 16

10 points on the line are obtained using the equation of the line and the desired x-values input into cells on MS Excel and presented here as follows;

(0, 16), (1, 12), (2, 8), (3, 4), (4, 0), (5, -4), (6, -8), (7, 12), (8, -16), (9, -20), and (10, -24)

8 0
2 years ago
You have a Mobile Legends account???<br>Can I play with You???​
yulyashka [42]

Answer:

yes oo you want to play with me

7 0
2 years ago
How many days has trump been a president
Free_Kalibri [48]
Hey there
_______________
The correct answer is
1 year, 64 days, 13 hours, 11 minutes and 44 seconds

__________
Hope this helps you
8 0
3 years ago
Read 2 more answers
Which two statements describe benefits of a block-based coding language
gladu [14]
Answer D and B I think
8 0
2 years ago
Read 2 more answers
Other questions:
  • Use the Internet and other sources to research the two disadvantages of standard biometrics: cost and error rates. Select one st
    10·1 answer
  • What does it mean to say that two variables are negatively correlated?
    6·1 answer
  • Which is the correct process for attaching a file?
    12·1 answer
  • An application programming interface (API) is ________. A) the code the application software uses to take advantage of code writ
    11·1 answer
  • Computer hardware without computer software is useless while computer software without computer hardware is meaningless. Discuss
    10·1 answer
  • A motorist is using the AHP to choose a new car from three possible models Arrow, a Bestmobile and a Commuter. The choice will a
    15·2 answers
  • How could you insert a new row between rows 20 and 21?
    7·2 answers
  • In the design phase of the systems development life cycle (SDLC), the _____ design is an overview of the system and does not inc
    10·1 answer
  • "Random Bars" is considered to be a Transition style<br> O True<br> O False
    11·1 answer
  • Write pseudo code that performs the following: Ask a user to enter a number. If the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!