Question: Bits. Write a program Bits.java that takes an integer command-line argument N and uses a while loop to compute the number of times you need

Bits. Write a program Bits.java that takes an integer command-line argument N and uses a while loop to compute the number of times you need to divide N by 2 until it is strictly less than 1. Print out an error message if N is negative.

% java Bits 0 % java Bits 8 0 4 % java Bits 1 % java Bits 16 1 5 % java Bits 2 % java Bits 1000 2 10 % java Bits 4 % java Bits -23 3 Illegal input 

Remark: This computes the number of bits in the binary representation of N, which also equals 1 + floor(log2 N) when N is positive. This quantity arises in information theory and the analysis of algorithms.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!