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
Name 3 supercomputers along with their cost, purpose and the country it is located.​
Alika [10]

Answer:

The three super computers are

a) Fujitsu Fugak

b) IBM Summit/IBM/Nvidia/Mellanox

c) Sunway TaihuLigh

Explanation:

Three super computers are as follows

a) Fujitsu Fugak - It is located in Kobe, Japan and its costs is ¥130 billion

b) IBM Summit/IBM/Nvidia/Mellanox - It is located in Oak Ridge, U.S. and it costs $325 million

c) Sunway TaihuLigh- It is located in Wuxi, China and it costs US$273 million

5 0
3 years ago
Which two components are configured via software in order for a PC to participate in a network environment
dalvyx [7]

Answer:

IP address and subnet mask.

Explanation:

The two components which are configured via software in order for a personal computer (PC) to participate in a network environment are;

I. IP address: it is an acronym for internet protocol address and can be defined as a unique number assigned to a computer or other network devices, so as to differentiate each device from one another in an active network system. Thus, an IP address is typically used to uniquely identify each computer or network devices connected to the internet or network.

In Computer networking, IP address are classified into two (2) main categories and these are; Local (internal) IP address and Global (external) IP address.

Also, the internet protocol (IP) address comprises of two (2) versions and these are; Internet protocol version 4 (IPv4) and Internet protocol version 6 (IPv6). An example of an IPv4 address is 192.168.1.0.

II. Subnet mask: this is a logical segmentation or subdivision of an internet protocol (IP) network so as to accommodate more hosts (computer systems). An example of a subnet mask is 255.255.0.0.

6 0
3 years ago
When Jimmy Fallon is outside the White House, his persona is mostly O A. humble O B. stern O c. gloomy O D. wild​
horsena [70]

Answer:

a

Explanation:

7 0
3 years ago
Answer: x = 3<br>#1 -2x + 5 = -31​
OLga [1]
#1 answer:X=-18
Mdkdkkdkdkdkkdkdkdk
3 0
3 years ago
Why the car floated before it started to sink? Explain.​
zhenek [66]

Answer:

it still had air in it

Explanation:

its simple

8 0
3 years ago
Other questions:
  • Word processing programs have different view options that you can use depending on the tasks you’re performing. Which option hel
    11·1 answer
  • To view the results of a saved query, right-click the query in the Navigation Pane and click ____ on the shortcut menu.
    7·1 answer
  • 6. Data are given in comma delimited text file for a toy rocket. The rocket is powered by pressurized water that is discharged f
    14·1 answer
  • You are considering creating a mobile app. Describe a basic statement for the app you would create and whether your app should b
    7·1 answer
  • Write a program that computes the minimum, maximum, average and standard deviation of the population over time for a borough (en
    6·1 answer
  • Indentation is useful to make the document easier to read. To increase the indentation of the paragraph, you press the increase
    10·1 answer
  • In what ways can information be slanted in a news report? List at least five ways.
    5·2 answers
  • 1. Choose a real or made up company, and describe at least three ways in which the company uses technology. (1-3 sentences. 3.0
    13·1 answer
  • Harry has created a Microsoft Excel workbook that he wants only certain people to be able to open. He should use
    13·1 answer
  • Why is my computer fans making weird noises?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!