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
If i find an image and copy and paste it into Paint.
Leokris [45]

Answer:

Lossy image formats will remove data during compression as a trade off for lower storage occupation. Lossless data formats will not remove data during compression, resulting in higher quality but also higher storage occupation.

Graphic Artists will almost always use lossless due to it delivering the highest quality image possible.

8 0
3 years ago
Its Inventiveness, uncertainty and futuristic ideas typically deals with science technology, what is it?
Margarita [4]

Answer:

It disrupt the established social contract, in the same way that invasive species do in natural ecosystems.

Explanation:

8 0
3 years ago
Read 2 more answers
Nikki sent flyers in the mail to all houses within the city limits promoting her computer repair service what type of promotion
Jlenok [28]

Direct marketing (APEX)


6 0
3 years ago
Read 2 more answers
Explique dos recursos que necesitan los empresarios para poder poner en práctica sus ideas.
nasty-shy [4]

ESPANOL: La explotación exitosa de nuevas ideas es crucial para que una empresa pueda mejorar sus procesos, traer productos y servicios nuevos y mejorados al mercado, aumentar su eficiencia y, lo más importante, mejorar su rentabilidad.

INGLES: The successful exploitation of new ideas is crucial to a business being able to improve its processes, bring new and improved products and services to market, increase its efficiency and, most importantly, improve its profitability

8 0
3 years ago
Read 2 more answers
What is most likely to happen to the purchasing power of money over time?
natima [27]

Answer:

A

Explanation:

6 0
2 years ago
Other questions:
  • Scratch and grinding marks on sedimentary rocks indicate which type of environment?
    6·1 answer
  • Your computer has gradually slowed down. What's the most likely reason?
    8·1 answer
  • On which tab are import and export commands located in Access? A. Home B. Database Tools C. External Data D. Create
    13·1 answer
  • Which of the following is not a type of user account? A. Administrator b. Guest c. Group d. Standard
    10·1 answer
  • Tom's Art Supplies used to sell art supplies through mail order catalogs, but the company's order takers often had difficulty de
    9·1 answer
  • What is the purpose of an internet protocol address (ip address)? it specifies whether a computer is using a broadband network o
    10·1 answer
  • How is communication within healthcare different than communication within other industries ?
    13·1 answer
  • A picture drawn in 3 d is called?​
    14·2 answers
  • Select the correct answers
    9·1 answer
  • Which of the following is an advantage of text HTML editors over plain text editors?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!