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
PLZ ANSWER ALL MY QUESTION. Which line of code will display the variable num rounded to the nearest tenth?
zavuch27 [327]

Answer:

A

Explanation:

5 0
3 years ago
Write Python code to save the data to a MongoDB collection:Import json module to parse JSON dataImport MongoClient from pymongo
Zigmanuir [339]

Answer:

Explanation:

The objective of this task is to compute a program that involves the usage of Python code to save the data to MongoDB and to query  the database.

Due to the error that occur which makes me to be unable to submit this answer, I've created a word document instead and the attached file can be found below.

Thanks!

Download docx
8 0
2 years ago
I'll give brainlist to right answers
xeze [42]
I think it’s number 1. Check the answer first.
5 0
2 years ago
What is modem please give me answer​
rjkz [21]

Answer:

a combined device for modulations and demodulations

4 0
3 years ago
1) If a robot has a 3 bit instruction set and needs 20 instructions to reach its destination, how many bits of memory are requir
mariarad [96]

Answer:

Explanat500,000ion:

8 0
2 years ago
Other questions:
  • Achieving a degree in computer forensics, information technology, or even information systems can provide a strong foundation in
    11·1 answer
  • Categories of general purpose application software and examples each​
    13·1 answer
  • There are several vehicles in a parking lot. Some of them are motorcycles
    8·2 answers
  • You are evaluating the bounce rate of your overall website traffic and find that users with a social media referral source have
    9·1 answer
  • What are the five types of alignment in Word?
    12·2 answers
  • In the URL, what is the subdomain and what is the domain name?
    5·1 answer
  • A ____ object is used to hold data that is retrieved from a database via the OleDbDataAdapter connection. a. DataRecord b. DataS
    12·2 answers
  • PLEASEEEEEE HELP, ILL DO ANYTHING JUST ANSWER THESE CORRECTLY!!!!!TYSM!!!
    15·2 answers
  • You are between flights at the airport and you want to check your email. Your wireless settings show two options:
    14·1 answer
  • Your program will be used by many departments at the university. Your comments will be important to their IT people. What would
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!