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
Henry is sent to work with a customer at the company’s satellite branch in another town. During his visit, he notices that most
Dmitriy789 [7]

Answer:

Correct option is B: Train the employees on why these issues are security concerns

Explanation:

When employees do not follow corporate guidelines regarding information systems and security, it is the duty of organizations to ensure that every employee knows the importance of following these guidelines due to the security risk the company might face. Hence, it is Henry's duty to ensure that he trains the employees on why their not following guidelines and looking at their personal emails are security concerns. This way he is sure that the employees are aware of the risks and any further breach in policy from them would require consequences.

7 0
3 years ago
I need to create a method named "root positive". which will either print the square root of the number passed to it or if the nu
rjkz [21]

Answer:

Explanation:

The following code is written in Java. It is a method that calculates the square root of a number as requested. The method first checks with an IF statement if the parameter value is a positive number and then calculates the square root and prints it to the screen. Otherwise, it prints Number must not be negative. A test case has been provided in the main method and the output can be seen in the attached image below.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.print("Enter a number of type double to calculate square root:");

       double num = in.nextDouble();

       rootPositive(num);

   }

   public static void rootPositive(double num) {

       if (num > 0) {

           System.out.println(Math.sqrt(num));

       } else {

           System.out.println("Number must not be negative.");

       }

   }

}

5 0
3 years ago
A _______________ is a field that contains data unique to a record.
Andru [333]

A primary key is a field that contains data unique to a record

8 0
3 years ago
I will give brainliest to the first person who can answer correctly.
Mariulka [41]
I think that the answer wiloukd be B. For #31 and for #32 A.
4 0
3 years ago
I know this isn't a school question but it is important! how do I get out of hp hardware diagnostics UEFI on hp pc? (step by ste
Debora [2.8K]

Answer:

1. Turn off the computer and wait five seconds.

2. Press the Power button to start the computer and repeatedly press the F10 key to enter the BIOS setup menu.

3. On the BIOS Setup screen, press F9 to select and load the BIOS Setup Default settings.

4. Press F10 to Save and Exit.

5. Use the arrow keys to select Yes, then press Enter when asked Exit Saving Changes?

6. Follow the prompts to restart your computer.

After you have get to the operating system,

1. Press CTRL + Alt + Del on the blank screen.

2. Click on Task Manager

3. Click "File" - "Run a new task" If there is no "file" option, please click on the task manager under the "details"

4. In the pop-up window, enter "msconfig" click "OK"

5. In the system configuration window that appears, click "Service" and uncheck "App Readiness".

6. Click "Apply" --- "OK"

7. In the following window appears to click on the "restart"

6 0
3 years ago
Other questions:
  • Google, Yahoo, and Microsoft search all use the same Web crawler.
    13·2 answers
  • Variables set equal to patterns are said to be:_______.
    7·1 answer
  • All of the following are reserved keywords in C++ EXCEPT
    5·1 answer
  • What is the film format that many filmmakers feel is superior to any other format?
    13·1 answer
  • The famous study entitled ""Protection Analysis: Final Report"" focused on a project undertaken by ARPA to understand and detect
    14·1 answer
  • Business cards are generally designed so that this item stands out the most.
    8·1 answer
  • - Which amongst the following is not a Characteristic of Cloud Computing?
    5·1 answer
  • What is an insertion point?
    6·1 answer
  • How to set Campaign goals?
    11·1 answer
  • What is the optimal number of members for an Agile team?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!