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
cestrela7 [59]
3 years ago
11

Write a Java program that reads an 8-bit binary number from the keyboard as a string and then converts it into decimal. For exam

ple, if the input is “01001101”, the output should be “77”. (Hint: Break the string into substrings and then convert each substring to a value for a single bit (i.e., 0 or 1). If the bits from right to left are b0, b1, …, b7; the decimal equivalent value is b0 + 2b1 + 4b2 + 8b3 + 16b4 + 32b5 +64b6 + 128b7.
Computers and Technology
1 answer:
cestrela7 [59]3 years ago
5 0

Answer:

public class Brainly

{

 public static void main(String[] args)

 {

   BinaryConverter conv = new BinaryConverter();

   String binStr = "01001101";

   System.out.print(binStr + " in decimal is "+conv.BinToDec(binStr));

 }

}

public class BinaryConverter

{

 public int BinToDec(String binStr)

 {

   int d = 0;

   while(binStr.length() > 0)

   {

     d = (d << 1) + ((binStr.charAt(0) == '1') ? 1: 0);

     binStr = binStr.substring(1);

   }

   return d;

 }

}

Explanation:

The program "eats" the string from left to right, and builds up the integer representation in variable "d" on the go. While there are digits left, it shifts the previous result to the left and sets the least signficant bit to 1 only if the corresponding string character is a 1.

You might be interested in
Which of the following are the differences between DDR3 SDRAM and DDR2 SDRAM? DDR3 transfers data at twice the rate of DDR2. DDR
Free_Kalibri [48]

Answer:

DDR3 SDRAM having twice rate of data transferring as compared to DDR2 SDRAM both have 240 pin connection. DDR3 memory power consumption is 40 % less as compared to DDR2. both are transfers data on a 64 data bits wide bus. The physical difference occur in both type a cut is present at bottom along pin in DDR2 it is occur probably in center and In DDR3 it is occur at left  through center.

7 0
3 years ago
Can an apple watch break or have a camera?
Viktor [21]

Answer:

apple watches can break, and they can deffinetly have cameras if they engineered right.

Explanation:

5 0
2 years ago
There is a feature that allows you to lock the document, to avoid others making changes. True or False
Burka [1]

Answer:

yes there is

Explanation:

6 0
3 years ago
Analyze the problem statement. Select the correct answer. Vision: We want to decrease errors in our billings to clients. Issue:
finlep [7]

Answer: This problem statement does not provide a useful issue statement.

3 0
3 years ago
Write a program in pascal to find the area of a circle
umka2103 [35]

Program Area_Circle;

Uses Crt;

Const

Pi = 3.1416;

Var

Radius : Integer;

Area : Real;

Begin

Clrscr;

Writeln('Area of a Circle Solver');

Writeln;

Write('Enter the Radius of the Circle : ');

Readln(Radius);

Area := (Pi * Radius * Radius);

Writeln;

Writeln('The Area of the Circle is ' ,Area:8:2,'.');

Writeln;

Writeln('Program Executed');

Readln;

End.

Hope this helps!

5 0
4 years ago
Other questions:
  • Two electronics technicians are discussing electrical quantities. Technician A says that resistance is an opposition to electric
    6·1 answer
  • When computer manufacturers overcame the enormous 13,000 Chinese character barrier by creating a workable keyboard through voice
    15·1 answer
  • 1.2 Data transmission speed.Unit of measurement used to measure in bits per second.1000 bits per second (bps)=
    11·1 answer
  • What is a tag in an HTML document?
    9·2 answers
  • Logic errors are easily identified when a program is compiled true or false
    10·2 answers
  • After compiling source code, which command still needs to be run in order to copy the newly compiled binaries into a directory l
    5·1 answer
  • Develop a program that implements the POLYNOMIAL ADT using the LIST ADT. The POLYNOMIAL ADT is used to represent polynomials and
    8·1 answer
  • A company decides to relocate its operations to another state in order to take advantage of some new business investment credits
    15·1 answer
  • Display all the natural numbers from 1 to 100 that are exactly divisible by 3 and 7 using FOR … NEXT. Without using Mod
    7·1 answer
  • What in the world is this for and how do you use it
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!