Help authour, Buy PDF Ebook >>>Click Here<<<
Data Structure Questions and Answers-Decimal to Binary using Stacks
Question 1 |
Express -15 as a 6-bit signed binary number.
1111 | |
101111 | |
101110 | |
1110 |
Question 1 Explanation:
The first 4 1s from the right represent the number 15, 2 more bits are padded to make it 6 digits and the leftmost bit is a 1 to represent that it is -15.
Question 2 |
Which of the following code snippet is used to convert decimal to binary numbers?
public void convertBinary(int num) { int bin[] = new int[50]; int index = 0; while(num > 0) | |
public void convertBinary(int num) { int bin[] = new int[50]; int index = 0; while(num > 0) | |
public void convertBinary(int num) { int bin[] = new int[50]; int index = 0; while(num > 0) | |
public void convertBinary(int num) { int bin[] = new int[50]; int index = 0; while(num > 0) |
Question 2 Explanation:
Take the modulus by 2 of the number and store in an array while halving the number during each iteration and then display the contents of the array.
Question 3 |
Which is the predefined method available in Java to convert decimal to binary numbers?
toBinaryInteger(int) | |
toBinaryValue(int) | |
toBinaryNumber(int) | |
toBinaryString(int) |
Question 3 Explanation:
The method toBinaryString() takes an integer argument and is defined in java.lang package. Usage is java.lang.Integer.toBinaryString(int) this returns the string representation of the unsigned integer value.
Question 4 |
Using stacks, how to obtain the binary representation of the number?
public void convertBinary(int num) { Stack<Integer> stack = new Stack<Integer>(); while (num != 0) { int digit = num / | |
public void convertBinary(int num) { Stack<Integer> stack = new Stack<Integer>(); while (num != 0) { int digit = num % | |
correctchoice
public void convertBinary(int num) { Stack<Integer> stack = new Stack<Integer>(); while (num != 0) { int digit = num
There are 5 questions to complete.
Help authour, Buy PDF Ebook >>>Click Here<<< |