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
The main circuit board of a computer is the _______. The ______ is located on the circuit board. The _____ is the circuitry that
Inessa05 [86]

Answer:

The main circuit board of a computer is the Motherboard. The Processor(CPU) is located on the circuit board. The Processor(CPU) is the circuitry that processes information. The CPU is also known as the brain of the computer. The speed of the processor is controlled by the clock. The system clock controls the timing of all computer operations.

Explanation:

4 0
3 years ago
I am trying to code a lifting simulator game on ro-blox. These problems listed in the third picture tells you the problems. If y
ipn [44]

Answer:

cool

Explanation:

3 0
2 years ago
Read 2 more answers
In a linked chain implementation of a queue, the performance of the enqueue operation
alexdok [17]

Answer:

A.O(1)

Explanation:

In the implementation of queue by using linked chain the performance of  the enqueue operation is O(1).We have to  maintain  two pointers one  head and the other tailand  for  enqueue operation  we have to insert element  to the next of the tail and then  make that element  tail.Which takes O(1) time.

4 0
3 years ago
Which of these tools stick to the edge of an image, thus making it easy to select the shape of an image (adobe Photoshop)
elena55 [62]

Answer:

Number 2 Polygonal lasso tool

Explanation:

5 0
2 years ago
What are the assignable addresses for the 12th subnet with the network address of 220.100.100.0 and the number of needed subnets
bogdanovich [222]

Answer:

C. 220.100.100.45 to 220.100.100.46

Explanation:

The Classless IP subnetting of 220.100.100.0 begins from the fourth octet of the IP address. To get 45 subnet mask, it uses 6 bits from the fourth octet, which approximately give 64 subnets, while the remaining 2 bits are used for host IP addressing.

The useable host IP addresses are gotten from the formula '2^{n}-2', with n=2 bits.

useable host IP addresses = 2^2 - 2 = 2 addresses per subnet.

While the 12th subnet is 12 x 2^2 = 44.

This means that the 12th subnet mask starts with 220.100.100.44 (as the network address) and ends with 220.100.100.47 as broadcast IP address, while '.45' and '.46' are the assignable addresses of the subnet.

5 0
3 years ago
Other questions:
  • Which of these printers would be the most suitable for printing a large number of high quality black and white printouts?
    15·1 answer
  • What operator is used to create a validation rule? A. – B. / C. &lt; or &gt; D. +
    12·1 answer
  • Describe the following software process models using your own words .Your explanation should also provide an example of a softwa
    12·1 answer
  • Which of the following commands contains an error?
    8·1 answer
  • "the magical number seven, plus or minus two" refers to the storage capacity of ________ memory.
    5·2 answers
  • Explain how being a metal, metalloid, or non-metal affects conductivity
    10·1 answer
  • Write a program that implement a bubble sort ?
    5·1 answer
  • A _________________________ can use SOAP headers to carry meta information in its messages. A. Web service B. REST Service C. Co
    14·1 answer
  • Which of the following is a valid HTML reference to a CSS file?
    13·1 answer
  • What's the commission payout for auto bill pay if sold with a ga?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!