vb.net converting integers etc..
#1
Scooby Regular
Thread Starter
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like
on
1 Post
![Post](https://www.scoobynet.com/images/icons/icon1.gif)
Im going brain dead today..
im trying to read a byte from a file...
say the value I want to read out is 71 (hex)
this is 113 dec.
I then want to do the following conversions
(((113 * 8) - 750)/750.6) * 14.5
So I have tried the following...
Dim fstream As FileStream = New FileStream("c:\file.bin", FileMode.Open)
Dim breader As BinaryReader = New BinaryReader(fstream)
fstream.Seek("35136", SeekOrigin.Begin)
Dim u As Integer
u = System.Convert.ToSingle(breader.ReadByte)
u = u * 8
u = ((u - 750) / 750.6) * 14.5
MSFlexGrid2.set_TextMatrix(row, col, u)
' close files
breader.Close()
fstream.Close()
obviously Ive snipped a bit of code here and there.. so row and col arent important...
which works ok execpt it returns 3. not 2.97 as I expect..
Im sure its the convert to single.. as the help says
Converts the value of the specified 8-bit unsigned integer to the equivalent single-precision floating point number.
so I presume its the single precision bit...
what should I be doing???
Help.. otherwise im hitting the bottle![Big Grin](https://www.scoobynet.com/images/smilies/biggrin.gif)
David
im trying to read a byte from a file...
say the value I want to read out is 71 (hex)
this is 113 dec.
I then want to do the following conversions
(((113 * 8) - 750)/750.6) * 14.5
So I have tried the following...
Dim fstream As FileStream = New FileStream("c:\file.bin", FileMode.Open)
Dim breader As BinaryReader = New BinaryReader(fstream)
fstream.Seek("35136", SeekOrigin.Begin)
Dim u As Integer
u = System.Convert.ToSingle(breader.ReadByte)
u = u * 8
u = ((u - 750) / 750.6) * 14.5
MSFlexGrid2.set_TextMatrix(row, col, u)
' close files
breader.Close()
fstream.Close()
obviously Ive snipped a bit of code here and there.. so row and col arent important...
which works ok execpt it returns 3. not 2.97 as I expect..
Im sure its the convert to single.. as the help says
Converts the value of the specified 8-bit unsigned integer to the equivalent single-precision floating point number.
so I presume its the single precision bit...
what should I be doing???
Help.. otherwise im hitting the bottle
![Big Grin](https://www.scoobynet.com/images/smilies/biggrin.gif)
David
#2
Scooby Regular
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes
on
0 Posts
![Post](https://www.scoobynet.com/images/icons/icon1.gif)
I've not done much .Net yet, but am I correct in thinking that the convert to single actually converts 'u' to a Single. If it does I'm stuck, but if not that's why you're getting the 3.
Don't need to use a format statement on it do you?
(I'll get me coat
)
Don't need to use a format statement on it do you?
(I'll get me coat
![Roll Eyes (Sarcastic)](https://www.scoobynet.com/images/smilies/rolleyes.gif)
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM