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
SHORT ANSWERS:
dem82 [27]

Answer:

Hard drive Microsoft have the highest priority actions

7 0
3 years ago
Which word processing tool can help you find synonyms to improve your word choice?
deff fn [24]
Grammarly is the answer
6 0
3 years ago
Read 2 more answers
RSA encryption relies on
oee [108]

Answer:

the difficulty in factoring large numbers

 a public key that the server and the user’s computer know

 

the use of prime numbers

a private key that only the server knows

Explanation:

ege 2021

5 0
2 years ago
How is the “conflict set” defined in Production systems?How conflict is resolved ?
Triss [41]

Answer:

The rules which could trigger at any period in time are referred to as the conflict set. A programming bug/conflict can occur when two programs compete for the same resource such as memory or register etc.

A Conflict Resolution Strategy is is a protocol which highlights which decision will be triggered first.

The best way to resolve conflict is to first determine the kind of conflict it is. Hardware conflicts can be resolved by first troubleshooting the hardware and in some instances unplugging the hardware causing the conflict.

When hardware creates conflicts it may be due to a driver issue. reverting to an old driver or updating the existing one may solve the problem.

Software conflicts can be resolved by installing updates or complete uninstallation.

Cheers!

5 0
2 years ago
Font changes can only be applied on a word-by-word basis.<br><br><br> A.True<br><br><br> B.False
Sergio039 [100]
B. False, it doesnt only have to be applied word by word


3 0
3 years ago
Read 2 more answers
Other questions:
  • Computers spend most of their time in loops, so multiple loop itera- tions are great places to speculatively find more work to k
    10·1 answer
  • What is the main storage device where the computer stores data?
    15·1 answer
  • Within a google form when looking which option do u use?
    13·1 answer
  • In a Microsoft® Word® document, if a user wanted to organize information in rows in columns, they should select a
    5·1 answer
  • Microsoft’s SharePoint server product dramatically altered the content and records management (RM) markets. Crocker (2015), edit
    6·1 answer
  • Your task is to create a bash shell script that is able to backup all the C++ program files in your current directory. The algor
    10·1 answer
  • When was kale discovered?
    9·1 answer
  • Could I use a prepaid card to buy a Brainly membership because I tried to get the trial with a low balance but more than like 5$
    11·1 answer
  • What would be the effect if the register contained the following values 10011000
    12·2 answers
  • Which of these are examples of an access control system? Check all that apply.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!