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
I need help with Microsoft.
Ipatiy [6.2K]
No clue bro. Im in middle school thats y
7 0
3 years ago
Which of the following is NOT correct concerning database design? Question 2 options: Identify all fields needed to produce the
PtichkaEL [24]

The option which is not correct concerning database design is identify all fields needed to produce the required information.

What is database design?

The database design is the arrangement of the data or the information, according to the model of database.

Let's check all the option one by one,

  • Identify all fields needed to produce the required information- This does not concern with the database design.
  • Group related fields into tables-A relation database design consist of one or more than one related table. These tables are used together when the information is required.
  • Determine each table's primary key- To determine the table's primary key, is the concern with the database design.
  • Organize each piece of data into its largest useful part-The database design is the organization of data in the model of database.

The option which is not correct concerning database design is identify all fields needed to produce the required information.

Learn more about the database design here;

brainly.com/question/25694408

8 0
3 years ago
What is a device driver
Elan Coil [88]

A device driver is a computer program that operates or controls a particular type of device that is attached to a computer.

5 0
3 years ago
The term which refers to the attempt to gain unauthorized access to systems and computers used bya telephone company to operate
Alex787 [66]

Answer: Phreaker

Explanation:

Phreaker is defined as the unauthorized attack on  authorized communication system for stealing and manipulation phone networks.

  • Exploring,searching and identifying telecommunication field with help of technologies,equipment,tools etc is done to exploit the system and resources .
  • Other options are incorrect because phone hacking is attacking phone device, [email protected] is also hacking source and hacktivist hacks system to impact social and political field.
  • Thus, the correct option is option(d)
8 0
3 years ago
Fill in the blank with the correct response. Wanting to become a better archer is a what?
Oksi-84 [34.3K]
Is a better archer shooter
5 0
3 years ago
Other questions:
  • HELLLLLP ill make you brainiest and ill give u a lot of points if you HELP ME Directions Part One.
    12·2 answers
  • For microsoft word tabs are very useful when you want to
    13·1 answer
  • What are the latest technology in 2014
    11·1 answer
  • Most new information systems must communicate with other, existing systems, so the design of the method and details of these com
    9·1 answer
  • Create pseudocode that could be used as a blueprint for a program that would do the following: An employer wants you to create a
    12·1 answer
  • It is a small hand tool used generally in decorative works such as making garnishes
    15·1 answer
  • In Java. Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element
    5·1 answer
  • Display the total number of parking tickets.
    5·1 answer
  • You have searched a database to locate US cities with population counts above 1 million people. You need to present the results
    6·2 answers
  • The events that happen in a story are called the _________________.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!