Binary to Decimal Conversion
-expand the binary number into a notation. The right significant bit will start at 0 exponent counting towards the left significant bit. Add the sum of product of exponentiation based 2.
Ex:
Convert 1012 to________10
Solution:
1012 =1x 22 + 0 x 21 + 1 x 20
=4+0+1
=5
Answer=510
Problem Solving: Write a program that asks a user to enter binary numbers as String (array of characters with size 20). Convert that binary numbers into an equivalent decimal number. Display the decimal number equivalent of that binary number on screen.
1. Declare a variable for the stack with a size of 20 elements; array of integers.
2. Traverse the elements of the string convert them into integer numbers push them into stack.
3. Perform a repetitive loop computation for the sum of products by popping the contents of the stack. It will repeat by the length of the string.
4.Display the decimal number on the screen.
use C++
-expand the binary number into a notation. The right significant bit will start at 0 exponent counting towards the left significant bit. Add the sum of product of exponentiation based 2.
Ex:
Convert 1012 to________10
Solution:
1012 =1x 22 + 0 x 21 + 1 x 20
=4+0+1
=5
Answer=510
Problem Solving: Write a program that asks a user to enter binary numbers as String (array of characters with size 20). Convert that binary numbers into an equivalent decimal number. Display the decimal number equivalent of that binary number on screen.
1. Declare a variable for the stack with a size of 20 elements; array of integers.
2. Traverse the elements of the string convert them into integer numbers push them into stack.
3. Perform a repetitive loop computation for the sum of products by popping the contents of the stack. It will repeat by the length of the string.
4.Display the decimal number on the screen.
use C++