473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert Byte Array to Array of Singles?

I have a file which, at a certain point, contains 40000 bytes. I need to go
through these bytes and for each four bytes I need to create a singles
ending up with 10000 singles.

This is how I'm doing it:

For i = 0 To 39999
fsNCodeFile.Read(arrBytes, 0, 4)
sngValue = BitConverter.ToSingle(arrBytes, 0)
'do something quick with sngValue
Next

Is there a quicker way to get these singles form the file? I know which byte
in the file to start and finish on and no other data apart from singles is
found between these points.

--

Cheers,

elziko
Nov 20 '05 #1
2 1364
It would be faster to read all the bytes at once and then convert them to
singles. This is a lot better than reading only four bytes at a time.

'-- Read all the bytes
fsNCodeFile.Read(arrBytes, 0, 40000)

'-- Then convert them
For i = 0 to 39999 Step 4
sngValue(count) = BitConverter.ToSingle(arrBytes, i)

count +=1
Next

"elziko" <el****@NOTSPAMMINGyahoo.co.uk> wrote in message
news:40***********************@news.easynet.co.uk. ..
I have a file which, at a certain point, contains 40000 bytes. I need to go through these bytes and for each four bytes I need to create a singles
ending up with 10000 singles.

This is how I'm doing it:

For i = 0 To 39999
fsNCodeFile.Read(arrBytes, 0, 4)
sngValue = BitConverter.ToSingle(arrBytes, 0)
'do something quick with sngValue
Next

Is there a quicker way to get these singles form the file? I know which byte in the file to start and finish on and no other data apart from singles is
found between these points.

--

Cheers,

elziko

Nov 20 '05 #2
In article <40***********************@news.easynet.co.uk>, elziko wrote:
I have a file which, at a certain point, contains 40000 bytes. I need to go
through these bytes and for each four bytes I need to create a singles
ending up with 10000 singles.

This is how I'm doing it:

For i = 0 To 39999
fsNCodeFile.Read(arrBytes, 0, 4)
sngValue = BitConverter.ToSingle(arrBytes, 0)
'do something quick with sngValue
Next

Is there a quicker way to get these singles form the file? I know which byte
in the file to start and finish on and no other data apart from singles is
found between these points.


System.IO.BinaryReader.ReadSingle

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 1 Days, 18 Hours, 9 Minutes, 42 Seconds
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
3
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte,...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
2
by: twawsico | last post by:
I have a piece of code that needs to read the contents of a binary file (that I've created with another app) into an array of structures. The binary data in the file represents just a series of...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.