Question

In: Mechanical Engineering

write a VBA code to convert an arbitrary positive binary fractional number (0< number<1) to equivalent...

write a VBA code to convert an arbitrary positive binary fractional number (0< number<1) to equivalent decimal number. the code should acquire the binary fraction number in the format"0.xxxxxx"from input box, then return the equivalent decimal number in a message box. in the code, you may need to use VBA function "mid(_,_,_)" to pick up a specific symbols or characters from a string. you can use below conversion as benchmark to verify and debug your code:

(0.1011)2 = (0.6875)10

  

Solutions

Expert Solution

Sub Binary_to_Decimal()
Dim B, B1, B2 As String
Dim i, A As Integer
Dim A1, D As Double

B = InputBox("please enter the Fractional binary number(0.xxxxxx)")
'B = 0.1011
B1 = Mid(B, 1, 1)
B2 = Mid(B, 2, 1)
If B1 = 0 And B2 = "." Then
D = 0
    For i = 1 To Len(B) - 2
        A = Mid(B, i + 2, 1)
        A = CInt(A)
        If A = 0 Or A = 1 Then
        A1 = Application.WorksheetFunction.Power(2, -i)
        D = D + A * A1
        Else: GoTo 1
        End If
    Next i
    MsgBox ("The equivalent Decimal number for given Fraction Binary number is equal to " & D)
Else
1       MsgBox ("Input is not in correct format")
End If
End Sub


Related Solutions

1) Convert negative fractional decimal number to 8-bit binary number: – 16.625 (use 2's complement binary...
1) Convert negative fractional decimal number to 8-bit binary number: – 16.625 (use 2's complement binary format) Hint: –17 + 0.375 Given the hint above, the fractional number will be divided into two parts, - Whole number, - Fractional part, must be positive (2) Proof to check that your calculation above is correct
(1) Convert negative fractional decimal number to 8-bit binary number: – 6.625 Hint: –7 + 0.375...
(1) Convert negative fractional decimal number to 8-bit binary number: – 6.625 Hint: –7 + 0.375 Given the hint above, the fractional number will be divided into two parts, - Whole number, - Fractional part, must be positive (2) Use 2's complement binary format to convert negative fractional decimal number to 8-bit binary number: – 6.625 (3) Proof to check that your representation calculation for (1) & (2) is correct
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
6.28 LAB: Convert to binary - functions Write a program that takes in a positive integer...
6.28 LAB: Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second...
Write a function printTwoLargest() that inputs an arbitrary number of positive numbers from the user. The...
Write a function printTwoLargest() that inputs an arbitrary number of positive numbers from the user. The input of numbers stops when the first negative or zero value is entered by the user. The function then prints the two largest values entered by the user. If no positive numbers are entered a message to that effect is printed instead of printing any numbers. If only one number is inputted, only the largest is printed out (see 2nd example below). Sample output:...
Write a program to convert the input numbers to another number system. 1. Decimal to Binary...
Write a program to convert the input numbers to another number system. 1. Decimal to Binary 2. Binary to Decimal 3. Hexadecimal to Decimal 4. Decimal to Hexadecimal 5. Binary to Hexadecimal 6. Hexadecimal to Binary The user will type in the input number as following: Binary number : up to 8 bits Hexadecimal number: up to 2 bytes Decimal number: Less than 256 As a result, print out the output after the conversion with their input numbers. The program...
Problem: Convert the following binary number to decimal. 1. 110101.101 Problem: Convert the following decimal number...
Problem: Convert the following binary number to decimal. 1. 110101.101 Problem: Convert the following decimal number to fractional binary representation. 1. 103.5625
1) Write a method that takes a string representing a positive binary number, and writes out...
1) Write a method that takes a string representing a positive binary number, and writes out the number in hex. (Extra credit opportunity. Write the method so that the input can be a binary number in two's compliment form.) 2) Write a method that takes an integer and writes out its value out in hex. You cannot use string formatting characters. 3) Write an encodeString method that encodes a string of ASCII Characters. Input: It takes two parameters: a) inputString:...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the...
Python program. Write a python program that can convert any radix-d (arbitrary base) number to the equivalent radix-e (another arbitrary base) number. Where e and d are members in [2, 16]. Remember, base 16 needs to be calculated as hexadecimal. So, if radix-d is input as a hexadecimal number, it needs to convert and output to desired base. Conversely, if base 16 is the desired output, then the output needs to show a hexadecimal number. Hints: The easiest approach is...
Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT