Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binary to normal number

Status
Not open for further replies.

Pryer

Programmer
Oct 24, 2005
12
US
My problem is that I have a digitizer that will send to my program a binary 3D point(X value, Y value, Z value). It will send three strands

example: 0000 0000 0100

Now I've already typed more about binary than I know, but how do I convert that into a normal number like 3.125? Sorry for the ignorance. Any help is appreciated!
 
Just out of curiosity, what country are you from? I ask because 3.125 in some countries means three thousand, one hundred and twenty five, and in others, it means three and one-eighth.

Binary is normally used to represent integral values, though there is an IEEE standard for interpreting single and double precision numbers from binary representation. To answer your question, though, we'd have to know whether you want to interpret them as integers or floating point numbers.

Lee
 
If it is a 3D point coordinate set, then you will need to convert it to 3 numbers. Is this what you want to do?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I found this function:

Private Function BinaryToDecimal(ByVal BinValue As String) As Long
Dim lngValue As Long
Dim x As Long
Dim k As Long
k = Len(BinValue) ' will only work with 32 or fewer "bits"
For x = k To 1 Step -1 ' work backwards down string
If Mid$(BinValue, x, 1) = "1" Then
If k - x > 30 Then ' bit 31 is the sign bit
lngValue = lngValue Or -2147483648# ' avoid overflow error
Else
lngValue = lngValue + 2 ^ (k - x)
End If
End If
Next x
BinaryToDecimal = lngValue
End Function

Here:
You can split your three strands to three seperate variables and use BinaryToDecimal() on each strand.

Note: It uses a string instead of a numeric variable.

-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top