I have problem in converting fraction binary to decimal

naveen5856

New Member
Joined
Jan 12, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I'am Unable to convert 1.00000110001001001101111 this fraction Binary Value to Decimal in Excel.
Help me with proper function to convert the above value.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try this
VBA Code:
Function BinaryToDecimal(b)
  Dim i, x, n, d, b1, b2
  n = InStr(b, ".")
  b1 = Left(b, n - 1)
  b2 = Mid(b, n + 1)
  x = 1
  d = 0
  For i = Len(b1) To 1 Step -1
    d = d + x * Mid(b1, i, 1)
    x = x * 2
  Next i
  x = 0.5
  For i = 1 To Len(b2)
    d = d + x * Mid(b2, i, 1)
    x = x / 2
  Next i
  BinaryToDecimal = d
End Function
 
Upvote 0
Try this
VBA Code:
Function BinaryToDecimal(b)
  Dim i, x, n, d, b1, b2
  n = InStr(b, ".")
  b1 = Left(b, n - 1)
  b2 = Mid(b, n + 1)
  x = 1
  d = 0
  For i = Len(b1) To 1 Step -1
    d = d + x * Mid(b1, i, 1)
    x = x * 2
  Next i
  x = 0.5
  For i = 1 To Len(b2)
    d = d + x * Mid(b2, i, 1)
    x = x / 2
  Next i
  BinaryToDecimal = d
End Function
No Not Working.
 
Upvote 0
I get 1.02400004863739
What are you expecting?
 
Upvote 0
This
same answer i'm expecting
formula gives it
Excel Formula:
=binarytodecimal("1.00000110001001001101111")
you may have to format the cell as text to stop Excel truncating the number
eg
Excel Formula:
=TEXT(binarytodecimal("1.00000110001001001101111"),"0.00000000000000")
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top