473,395 Members | 1,377 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,395 software developers and data experts.

Reading Binary Data.

Ady
Hi,

I am trying to create an editor and the structure of our existing files are
as follows.

In C# how would I read the following binary data from a file and convert it
into usable data.

// c code
typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char version;
TRIANGLE[];
}

Any help appreciated

Ady.
Nov 15 '05 #1
2 3218
Ady,
You can use Serialization or System.IO.BinaryReader.

With Serialization the system does most of the work for you, with
BinaryReader & BinaryWriter you have to do more of the work.

For details on Serialization see:

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

For BinaryReader see:
http://msdn.microsoft.com/library/de...ClassTopic.asp

Hope this helps
Jay
"Ady" <ad**********@tcm.co.uk> wrote in message
news:uN*************@TK2MSFTNGP11.phx.gbl...
Hi,

I am trying to create an editor and the structure of our existing files are as follows.

In C# how would I read the following binary data from a file and convert it into usable data.

// c code
typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char version;
TRIANGLE[];
}

Any help appreciated

Ady.

Nov 15 '05 #2
Ady
Thanks for this.

I just have one more question if the format of the file is as follows,

typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char Ver;
char header[90];
unsigned int offsetTextures;
TRIANGLE tri[];
} MyFile;

How could I pull out the value off offsetTextures and add it on to the
beginning of the file to get the offset to the start of my texture data.

an example would be much appreciated.

Ady.
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl...
Ady,
You can use Serialization or System.IO.BinaryReader.

With Serialization the system does most of the work for you, with
BinaryReader & BinaryWriter you have to do more of the work.

For details on Serialization see:

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

For BinaryReader see:
http://msdn.microsoft.com/library/de...ClassTopic.asp
Hope this helps
Jay
"Ady" <ad**********@tcm.co.uk> wrote in message
news:uN*************@TK2MSFTNGP11.phx.gbl...
Hi,

I am trying to create an editor and the structure of our existing files

are
as follows.

In C# how would I read the following binary data from a file and convert

it
into usable data.

// c code
typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char version;
TRIANGLE[];
}

Any help appreciated

Ady.


Nov 15 '05 #3

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

Similar topics

20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
6
by: John Wright | last post by:
I am trying to read the data from a device on a serial port. I connect just fine and can receive data fine in text mode but not in binary mode. In text mode the data from the device comes in...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.