Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Binary - Float32 Conversion To String


My program is receieving a binary string which i'm "decoding" into ascii. I had a problem with converting an integer. Someone suggested this code. This works fine but sadly i have no idea why it works. I assumed that since integers and floats are both 4 bytes long that this code would be able to convert a float. However it dosent. I get an overflow error. So does anyone have an idea as to how i can convert a binary float32 into ascii?

Code:Player(i).Fra = (Mid(strData, c, 4))
temp1 = Asc(Mid(Player(i).Fra, 1, 1))
temp2 = Asc(Mid(Player(i).Fra, 2, 1)) * 256
temp3 = Asc(Mid(Player(i).Fra, 3, 1)) * 65536
temp4 = Asc(Mid(Player(i).Fra, 4, 1)) * 16777216
Player(i).Fra = temp1 + temp2 + temp3 + temp4





Edited by - n^^b on 9/10/2003 12:06:57 PM




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Binary - Float32 Conversion To String[unresolved]
My program is receieving a binary string which i'm "decoding" into ascii. I had a problem with converting an integer. Someone suggested this code. This works fine but sadly i have no idea why it works. I assumed that since integers and floats are both 4 bytes long that this code would be able to convert a float. However it dosent. I get an overflow error. So does anyone have an idea as to how i can convert a binary float32 into ascii?


VB Code:
Player(i).Fra = (Mid(strData, c, 4))    temp1 = Asc(Mid(Player(i).Fra, 1, 1))    temp2 = Asc(Mid(Player(i).Fra, 2, 1)) * 256    temp3 = Asc(Mid(Player(i).Fra, 3, 1)) * 65536    temp4 = Asc(Mid(Player(i).Fra, 4, 1)) * 16777216    Player(i).Fra = temp1 + temp2 + temp3 + temp4

Binary To String Conversion
I need help converting a set of binary numbers in a textbox (txtInput) to another textbox (txtOutput). I'm completely lost. Please Help.

For example:
txtInput has the following text in it:

0100100001101001

and i need txtOutput to display

Hi

Conversion Binary To Binary And Conversion Of Hexadecimal To Decimal In Calculator
Hi Folks

i was develop one scientific calculator

1) binary to binary conversion= for example we can add one binary value (1110) + another binary value(0101) = i want this output(100 1 1)but it comes 1211 this is my question how can i rectify ?

2) convert from hexadecimal to decimal conversions (ex)in decimal 12 to hexa is c . it wirks good ,but my question is how to convert hexadecimal to deimal (12) ?
Tks in Advance
----------------------------------------------------------------------
HARD WORK NEVER END FAILS"

Conversion To Binary
Hi all,
I'm currently building an application which my own style of themes which I have designed using an Image and four sets of strings but what I would like to do is to put all of it together so I have:

----------------------------
FILE_HEADER
----------------------------
BCOLOR | CCOLOR | FCOLOR
----------------------------



BKGIMAGE



---------------------------

FILE_HEADER = This is so the application knows that the correct file is loaded/Saved
BCOLOR = This is the background colour of the labels used in the application
CCOLOR = This is the current colour of the label thats currently hovered over
FCOLOR = This is the foreground colour of the labels used in the application
BKGIMAGE = This is the background image that will be used when the theme is loaded

and I would like to convert it to binary or the otherway round, convert the seprate parts to binary then combine them into a file.
How would I go about doing something like that.

Thanx From Luke

Binary Conversion
i'm working on a winsock based webserver, as of now, the browser connects and sends request information properly, my program gets the header in binary, so if you throw it into a text box or something it just looks like ?????????????????????????????????????????????????????????????????????? ???????????????????????????????? (i'm sure you knwo what i mean) but if you open a txt file for binary access and put the binary into it you can open the txt and see the proper header, my question is... how do i convert the ?????????????????????????????????????????????????????????????????????? ??? to the proper header without putting it into a file, then reopening the file and reading out of it? lol

Binary Conversion
How do i go about converting binary code into letters and words?

I have aboslutly no clue what to do

Binary And Hex Conversion
does anyone know how to to read a binary file, convert it to hex and display it in a text box? and then to take hex and convert it into binary and reassemble the binary file?

Binary / Hex Conversion
I am in my registry trying to decode this into text:

3Z7+9qrKSi9CGI8P8/51Hd2e/vaqykovQhiPD/P+dR0=



AND:

(view .jpg attachment)



Is there any programs that would decode this?

Binary Conversion
is there any function that convert a decimal number in to binary number .....

Binary Conversion
is there a fuction to convert a number to binary if not how do i do it...

thanks

brooke

Binary Conversion
ITtoolbox Portal for Visual Basic - http://visualbasic.ittoolbox.com/

I have a string of 2 integers (both 8 bit numbers) that were created by
taking a 16 bit number and turning it into 2 8bit numbers... I need to
figure out how to convert the 2 8bit numbers back to 1 16bit number... any
ideas/suggestions?

Robert Phillips
Systems Analyst
Chamberlin Edmonds and Associates
404-634-5196 x1261



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~

Hex To Binary Conversion
Hi I need to convert a hex number into its binary format in order to check the individual bits can anyone help
an example would be hex A9 to be converted to 10101001 can anyone help ??

Binary Conversion....
How do you convert a binary code to readable text?

--Ant

Conversion To Binary And Bit Testing ?
Hi there ! I'm a hardware design/ microcontroller programmer guy who has just recently taken to VB to help me control projects on the outside world.

Does VB provide a way to:

A/ Convert a number into binary (i.e. 227 = 11100011 ) ?

and

B/ Test those binary bits to determine if each is hi or low ?

I want to be able to convert a number into binary, rotate through it and toggle a parallel port line according to whether each bit is hi or low...Sort of serial output via a parallel port line if you will.

(This is simple to do in the microcontroller world.)

Thanks.

Decimal 2 Binary Conversion
Hello everyone...

Could anyone tell me how to convert an integer less than 25 into a 4 bit binary number

Binary/Decimal Conversion
Ok: i was looking at this thread: http://www.xtremevbtalk.com/show...ary+conversion
and i thought it would be really cool to make a program that converts binary to decimal, and vice versa..

This code works great

Code:
Dim Binstr As String
Hexstr = Hex$(number)
For LV = 1 To Len(HexStr)
Select Case Mid$(Hexstr, LV, 1)
Case "0"
BinStr = BinStr & "0000"
Case "1"
BinStr = BinStr & "0001"
Case "2"
'and so on.
Case "15"
BinStr = BinStr & "1111"
End Select
Next

The thing is, i dont understand why.. can someone please explain it to me?

Binary Conversion Function
I was looking through all of the functions in the object browser to find something to convert degrees to radians and vice versa without the math (180/pi , ooh, how difficult) . I saw that there was no function to convert to binary, but you could convert to hex and decimal and octal. Is there some kind of API function that will convert to binary?

Binary To Text Conversion?
I have a .bin file that I need to get some information out of. I need to be able to convert it into either decimal values, or text. I have another program that can read this, but I need to be able to convert it myself, and use the values that are in the file. Does anybody have any clue how to do this? Let me know if you need more info.

I have attached the file, and all you have to do is change the .txt back to .bin if you need to.

Decimal To Binary Conversion
I need someone to confirm that this code I've written will turn an integer value under 255 into a 8 bit binary without error (counter is the integer to be changed, and tempdata is a public string holding the return binary code). Thanks in advance...


Code:
Function BinaryConvert(convert As Integer)



If convert > 255 Then
MsgBox "Too big to convert", vbOKOnly, "Not Convertable"
Exit Function
End If

If convert <= 255 And convert > 127 Then
tempdata = tempdata & "1"
convert = convert - 128
Else
tempdata = tempdata & "0"
End If

If convert <= 127 And convert > 63 Then
tempdata = tempdata & "1"
convert = convert - 64
Else
tempdata = tempdata & "0"
End If

If convert <= 63 And convert > 31 Then
tempdata = tempdata & "1"
convert = convert - 32
Else
tempdata = tempdata & "0"
End If

If convert <= 31 And convert > 15 Then
tempdata = tempdata & "1"
convert = convert - 16
Else
tempdata = tempdata & "0"
End If

If convert <= 15 And convert > 7 Then
tempdata = tempdata & "1"
convert = convert - 8
Else
tempdata = tempdata & "0"
End If

If convert <= 7 And convert > 3 Then
tempdata = tempdata & "1"
convert = convert - 4
Else
tempdata = tempdata & "0"
End If

If convert <= 3 And convert > 1 Then
tempdata = tempdata & "1"
convert = convert - 2
Else
tempdata = tempdata & "0"
End If

If convert <= 1 And convert > 0 Then
tempdata = tempdata & "1"
convert = convert - 1
Else
tempdata = tempdata & "0"
End If


End Function

ASCII To Binary Conversion
Which function in VB accepts ASCII numbers (or string character) and returns its Binary equivalent.

e.g. I should pass it 65 (ascii of A), it should return 01000001, etc.

And which one does the opposite, I pass it binary and it should return its ascii.

Thanks,

Pradeep

Binary To Text Conversion
I have a .bin file that I need to get some information out of. I need to be able to convert it into either decimal values, or text. I have another program that can read this, but I need to be able to convert it myself, and use the values that are in the file. Does anybody have any clue how to do this? Let me know if you need more info.

I have attached the file, and all you have to do is change the .txt back to .bin if you need to.

Binary File COnversion
Hi All,

Is there any tool available to convert binary files to text files.If so plz give me the url or the application.Plz treat this as urgent.

Binary To Decimal Conversion
1.Iam a nerd vb programmer lured by the beauty of it.I want to explore more in it.I want to view data from excel application in a text box.I don't want to use data control.I want it to be done through an object of excel dll.
I thank any one who helps me to find a solution for it.I require the coding also as I am new to excel communication.


2.How to do digital to analog or binary to decimal conversion in vb.I require the coding also as I am new to this type of programming.

I appreciate and thank the person who helps me to solve the above problems.




any one with a solution can contact me at:s_subbarayan@yahoo.com

Binary To Text Conversion
I have a .bin file that I need to get some information out of. I need to be able to convert it into either decimal values, or text. I have another program that can read this, but I need to be able to convert it myself, and use the values that are in the file. Does anybody have any clue how to do this? Let me know if you need more info.

If you feel you need the file then email me at dhenson@uss.com

Binary-Decimal Conversion Problem
Been a long time since i've posted last- but I come with an intresting problem


I'm building a little Binary to Decimal converter for my new encryption program im building, when I come to the problem of Deconverting Binary to Decimal... Heres the deal, I have a 4 digit Decimal number encoded as 4 sets of 7 bit binary numbers.


Code:
'StrEMBin = strBinaryNumber <-- when I get it all done i should be able
' to just input a binary number, fornow, i use the below, just a random
' number I made up.
StrEMBin = "1011010001000100000011010101"

now, alls well an good till i try to take this number to an array, called StrDecode()


Code:
'StrEMBin = strBinaryNumber
StrEMBin = "1011010001000100000011010101"
X = Len(StrEMBin)
I = X / 7

Do While Not I = 0
StrDecode() = Mid(StrEMBin, X - 7, X)
X = X - 7
I = I - 1
Loop

the only way i could think to place the 7 numbers was by a mid( function, and the only way i could think to change where the numbers came from, while not making my array limited by a for loop, was via that do loop.
Unfortunatly, i get a type mismatch on the


Code:
StrDecode() = Mid(StrEMBin, X - 7, X)

line, any help is appreciated, following are all the relevant parts of my program, its a little big to paste onto here, and most of it doesnt pertain to this.


Code:
Dim StrEMBin As String, DeCo As String
Dim StrDecode() As String, StrDec As String

Dim X As Integer, Y As Integer, Z As Integer
Dim I As Integer, J As Integer, K As Integer

Dim IntDec As Integer


'.....
'.....
'.....


Public Sub BinToDec()


'StrEMBin = strBinaryNumber
StrEMBin = "1011010001000100000011010101"
X = Len(StrEMBin)
I = X / 7

Do While Not I = 0
StrDecode() = Mid(StrEMBin, X - 7, X)
X = X - 7
I = I - 1
Loop


For J = 0 To UBound(StrDecode)
DeCo = StrDecode(J)

K = Len(DeCo)

Do While Not K = 0
Z = Mid(DeCo, K - 1, K)
If Z = 0 Then
IntDec = IntDec
Else
IntDec = IntDec + (2 ^ (Abs(Y - 7)))
End If
Y = Y - 1
StrDec = StrDec & " " & IntDec
Loop
Next J
Text1.Text = StrDec
End Sub

Conversion From Ascii To Binary Format
hello ,

is there any direct function of converting ascii values to binary format.

thanks
nice day
jyothi

Excel Decimal To Binary (32 Bit) Conversion
Hi guys. I'm trying to write an Excel function that will take a 32 bit integer and calculate its binary equivalence, however I have very little experience with VisualBasic and was wondering if somebody could give me an idea of how I'd go about doing this.

Thanks.

Text To Binary File Conversion
Hello

Is there any utilities/activeX/source code which I can use to convert an ascii text file into a binary file????
Thanks!

Binary Files To Text File Conversion
Hi...

I have a binary file with extension .dat which was created using 'c' language. but now i would like to convert that file into text file using visual basic. how it is possible in VB?

with thanks

pradeep

Serial Port Binary Data Conversion
I've searched the forum and although some threads come close, none answer my question. I have a data acq box that transmits data via RS232. The data is binary with two header bytes (250 or 11111010) and one EOM byte (254 or 11111110). The data that I'm interested in resides in the 28 bytes in between the headers and EOM. I can connect to the box and receive data but I can't figure out how to parse it and use it. If I try to put it in a text box a get a lot of ? and some random characters. I know the box is working because I used a port monitor setup for binary and was able to see all of the data. My problem is how do I collect the data, identify the headers and EOM, parse the bytes and convert the data into a number that I can assign to a varible and use to set the properties of a gauge. I wrote a function to convert a byte to a number but I think it needs 1 and 0 characters for it to work. I don't want to convert it to characters unless I have to. I rather just convert it to numbers. Also, most are single byte data but some of the data requires two bytes. How does that change things. Thanks

Float32?
Im not quite sure how to ask this...but here goes

Um, im using winsocks and i send a sting a server, then it responds with series of packets that contains (string) (byte) and (float32) i need to know what number the float32 packet is, it is in ascii, and if i convert the ascii code to a number its not right, can someone expain to me what the float32 is and how to get the right number?

Convert A Int32 To A Float32 *RESOLVED*
I need to know how to convert a Int32 to a Float32. Can anyone help?

Value To String Conversion
lets say i key-in a value, (number or text) in a cell in MS Excel, how to convert the value of that cell into string so that i can do some changes to it, and then return the value (text)to another cell?

and thanks a lot for ur previous reply..it helped a lot!!

String Conversion
I am retrieving a checkbox value from the registry. When I save the value to the registry it saves it as True or False. When I call the setting I get a "Type Mismatch" error because it is expecting a 0 or a 1. So I think I convert to a value. This is what my code looks like, but it doesn't work. My savesetting works, but the GetSetting doesn't.

Code:
Private Sub Form_Load()

On Error GoTo ShowSplash 'If no registry key is found
Check1.Value = Val(GetSetting("Budget Master", "Startup", "ShowSplash")) '?
If Check1.Value = True Then
Form1.Show
Unload Me
Exit Sub
ElseIf Check1.Value = False Then
Me.Show
End If
ShowSplash:

End Sub
Isn't this how to convert the string to a value?

String To Hex Conversion ?
Hi

Is it possible to load a binary file in to a string and then convert the strings contents in to Hex ?

or would reading the binary file in to a byte array be the only option ?

regards
paul
uk

String--&gt;Int Conversion
If given a string, "32" for example, what is the function to convert it to an integer?


Thanks,
Tek

String Conversion
VB Code:
Dim s As StringDim x As Integer''Which is best?x = Val(s)'or:x = CInt(s)

I know there are subtle differences like those having to do with decimal separators, but what are the major advantages and drawbacks of either one?

String Conversion
hi everybody

i need to take a real number (dbl) and to put it into a string of predefined shape.

my number will be from 0.001 to 99.999
my string must be 00000000.001000 to 00000099.999000

i can do this converting dbl to str and concatenate with remaining
zeros, however have to break it to more cases ( even now i do not know how to check after dot how many figures i have) so i am wondering if it is there any command just to fill up my string with the necessary zeros.

now actually my string should be like this

"# s V x x x _ + d d d d d d d d . d d d d d d _ $ h h "
where xxx is a variable and dddddddd.dddddd my number
hh is the checksum of "# s V x x x _ + d d d d d d d d . d d d d d d _ " in hex

is there any function to calculate the checksum of a string?

now i am beginner in vb and i guess i will manage in a time (looong time) to figure it out but i would gladly accept any hint to help me out

thanks everybody
marian

String Conversion
i opened a ms access file and i open the table.. in the table, there is one field which data type is "memo" and i saw this text;

"G3d34fUWFubSl8yVEXi6Xjl8fPEc6iKyKykTCTDZY0akJUk03DYdjz13aEGLar+x/rReA1B+A6EoU3N5fklJxA==" (no quotation)

i dont know what language is that?? how can i convert it to the exact meaning of it?? what i mean is the right word? the right letter??

Hex To String Conversion
I'v searched the forum and i foud some exemples about how to convert hex to string but they don't seem to be working as i wanted, so, is there any way to convert this hex:

626c61626c61 to blabla

?

EDIT: Nvm, just found how to hehe

Here is the code:


VB Code:
Public Function HexToStr(ByVal Data As String) As StringDim Buffer As String     If Len(Data) Mod 2 <> 0 Then        HexToStr = vbNullString    Else        For i = 1 To Len(Data) - 1 Step 2            Buffer = Buffer & Chr("&H" & Mid(Data, i, 2))        Next i        HexToStr = Buffer    End IfEnd Function

String To HEX Conversion
This thread has been continued, as a new version, from my previous post: here

Ok here is the new part to my main thread of HEX and string conversion, back and forth now!

Of course, you can visit the RESOLVED thread for HEX to string Conversion here:

http://www.vbforums.com/showthread.p...hreadid=254790

Right onto the question. Is there a method at which I could convert a line of text into a line of HEX code? I dont really care how i do it, It can be just like the code in my previous thread (or similar) i dont mind. Or it could be completely new, which is better because we explore a wider range that way.

So the question is basically asked "How can I convert a string into HEX?"

Thanks, I hope you will benefit from this post as much as you will!

Cya

HEX To String Conversion
Hi everyone,

now this subject may look kind of repetetive, but i need help here.

I have searched the net, and these forums, but came up with nothing.

I am making a program which can convert HEX code into a string. So far it works great, for code which looks like FF FF FF FF

but if u get FFFFFFFF it goes mad. I have used Error handlers to prevent it from crashing, so its all ok. But i need another version of it. Many of the time i get code which does looke like FFFFFFFF and not FF FF FF FF and it just takes way too long putting the spaces in.

The code i have (taken from another post, thanks to the poster!) is

VB Code:
Private Sub cmdConvert_Click()Dim temp() As String     temp = Split(txtHEX.Text, " ")        txtString.Text = ""        For i = 0 To UBound(temp)        On Error GoTo ErrHandler                    txtString.Text = txtString.Text & Chr(HexToDec(temp(i))) & " "            Next i    ErrHandler: End Sub

It may look crap, but it works, and that Errhandler thing, hehe yup it doesnt crash anymore.

Please dont comment or suggest ways of improving my syntax or way of the code i have edited so much. But please help me with this problem.

There is also the HexToDec bit at the bottom, but i will only post that if u ask.

I have added two option buttons, one called Spaced, and one called Together. So i think you can guess what they mean.

When spaced is true, the above code can work for whats in the box fine. But if Together is true, i need new code which can convert HEX code, without spaces in, into strings.

Thanks to anyone who can help me, i really appreciate this. I have just tryed and tryed and had no success. I even tryed duplicating that and removing the " " bits etc... but no luck.

Thanks again

String Conversion?
Ive been working on a TCP/IP Logon Class, and the core of it
is just numbers translated to there ASC characters...

The challedge is each ASC character in my strings are 2 bytes.

Is it possible to make the unicode string a different type of string
so that it only supports those characters, and it would use 1 byte per character???

If my theory is somehow off, just tell me =)

Thanks

String Conversion HELP!!
How to I get this:

ethan.mp3

from this:

c:/hello/goodbye/test/ethan.mp3

Using string coversions. Thanks!

String Conversion
I am trying to read a value from a table. It is a rate for shipping. I need to output it into a flat file that does not have any decimal places. I am trying to do a string conversion before I write to the flat file. Also the field needs to be 5 characters long in the flat file.

My problem is first how to replace a decimal with nothing and then make sure the field is 5 characters long.

If it is 5.01 it need to be 501. I can do this fine, but when I get a 12 for $12 dollar or a 5.2 for $5.20 I am having problems replacing the decimal and then make sure the correct amount of characters appear. Should I add the zeroes first then remove the decimal? Or vice versa?

String Conversion
Hello All,

I am trying to find out how to determine the data type from a variable passed into a function, which then converts the variable into a string if it already isn't one. It goes something like the code below, but I am stuck on the first bit. Any help would be appreciated.

Regards
Nathan

Private Function stringConvert(strC) as String
If strC is an Integer then ' This is the line I need
strC = Cint(strC)
Else
strC = strC
End If
End Function

String Conversion
hi everybody

i need to take a real number (dbl) and to put it into a string of predefined shape.

my number will be from 0.001 to 99.999
my string must be 00000000.001000 to 00000099.999000

i can do this converting dbl to str and concatenate with remaining
zeros, however have to break it to more cases ( even now i do not know how to check after dot how many figures i have) so i am wondering if it is there any command just to fill up my string with the necessary zeros.

now actually my string should be like this

"# s V x x x _ + d d d d d d d d . d d d d d d _ $ h h "
where xxx is a variable and dddddddd.dddddd my number
hh is the checksum of "# s V x x x _ + d d d d d d d d . d d d d d d _ " in hex

is there any function to calculate the checksum of a string?

now i am beginner in vb and i guess i will manage in a time (looong time) to figure it out but i would gladly accept any hint to help me out

thanks everybody
marian

String Conversion
Is there anyway to convert the string "objcontrol.DatabaseName" into the actual object property so I can assign a value to it?

This is an example of a procedure call I might use.

Call ControlEnumeration("dat", g_strDbName, Me.Controls, 3, "objControl.DatabaseName")

I created the below procedure to be able to enumerate different types of controls and assign values to specified properties. I'm not sure if I'm going about this this right way.

Public Sub ControlEnumeration(controlTag As String, strValue As String, ctlControl As Object, intEndPosition As Integer, strProperty As String)
Dim objControl As Control
For Each objControl In ctlControl
If Mid(objControl.Name, 1, intEndPosition) = controlTag Then
strProperty = strValue
End If
Next
End Sub

String Conversion
Hello,
I have a fairly large text file set up something like below:
1-27-1990; : 8,19,35,39,42,43
2-3-1990; 9,11,13,20,36,37
2-10-1990; 1,11,15,21,32,39
2-17-1990; 1,2,10,18,23,29
2-24-1990; 21,25,30,31,38,40
3-3-1990; 2,17,18,21,26,41
3-10-1990; 9,17,21,23,27,37
3-17-1990; 5,10,15,17,31,43
3-24-1990; 1,8,9,38,40,43
3-31-1990; 5,32,36,37,40,42

I am trying to take out the date section of each line and write the date to a database. How can I extract say 1-27-1990 from the first line and write it to a date field. I don't help in the actual write to the database or opening the text file, just extracting the partial string in a format that can be put in the date field.
Thanks for any suggestions
Todd

Copyright 2005-08 www.BigResource.com, All rights reserved