472,357 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Big Endian Format

I receive a file from a client and the first 8 bytes are in Big Endian
format to denote the length of the following data. This is one of the
security requirements. I also have to do the same thing when sending a
response file back to them. Does anyone know an easy way to convert this
Big Endian format from/to an integer easily to make it easy to work with?

Thanks,

Matt

Nov 23 '05 #1
4 4542
Matt wrote:
I receive a file from a client and the first 8 bytes are in Big
Endian format to denote the length of the following data. This is
one of the security requirements. I also have to do the same thing
when sending a response file back to them. Does anyone know an easy
way to convert this Big Endian format from/to an integer easily to
make it easy to work with?


I guess you can use IPAddress.NetworkToHostOrder() here.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 23 '05 #2
Matt <md*****@sorvive.DONT-SEND-SPAM.com> wrote:
I receive a file from a client and the first 8 bytes are in Big Endian
format to denote the length of the following data. This is one of the
security requirements. I also have to do the same thing when sending a
response file back to them. Does anyone know an easy way to convert this
Big Endian format from/to an integer easily to make it easy to work with?


I have some classes to help with this kind of thing in my miscellaneous
utilities library.

See http://www.pobox.com/~skeet/csharp/miscutil

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 23 '05 #3

"Matt" wrote:
I receive a file from a client and the first 8 bytes are in Big Endian
format to denote the length of the following data. This is one of the
security requirements. I also have to do the same thing when sending
a response file back to them. Does anyone know an easy way to convert
this Big Endian format from/to an integer easily to make it easy to
work with?


You could store the bytes in an array and convert them with the
BitConverter class. If the bytes are sent from the MSB to LSB, you could
store them in the array starting at Length - 1 index (7th, in this
case). Since you know the size of the array beforehand, this shouldn't
be hard. Once you have the array filled, you can convert it to an ulong
or long (seeing that it's an 8 byte number) using the appropriate method
in the BitConverter class.

When you're ready to send the length back, you can call
BitConverter.GetBytes to get a byte array representing the number.
Reverse the array with Array.Reverse, or start at the end of the array
(Length - 1) and work your way through the array sending the bytes.

I'm fairly certain this will work, but would appreciate any corrections
if I'm mistaken about something.
Nov 23 '05 #4
Thanks to everyone that responded to this, I believe I have found a solution
based on your recommendations. ;)

"Matt" <md*****@sorvive.DONT-SEND-SPAM.com> wrote in message
news:Oc**************@TK2MSFTNGP09.phx.gbl...
I receive a file from a client and the first 8 bytes are in Big Endian
format to denote the length of the following data. This is one of the
security requirements. I also have to do the same thing when sending a
response file back to them. Does anyone know an easy way to convert this
Big Endian format from/to an integer easily to make it easy to work with?

Thanks,

Matt

Nov 23 '05 #5

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

Similar topics

2
by: Amit Gaur | last post by:
Hi newbie to python here, I have a binary file and i need to change the endian format..little to big as well as vice versa..could anyone help me out. thanks ---------------------------------...
0
by: Ernst Murnleitner | last post by:
Dear readers, Maybe someone can help: I need to exchange data with a PLC. My computer (Linux on intel) uses the intel format (little endian), the other device uses the motorola format (big...
3
by: Joe C | last post by:
I have some code that performs bitwise operations on files. I'm trying to make the code portable on different endian systems. This is not work/school related...just trying to learn/understand. ...
3
by: ranjeet.gupta | last post by:
Dear All !! I am not sure the question which I am asking is correct or wrong, but I have heard that storing the data into the big endian helps in gting the more transfer rate, Means we can...
14
by: ThazKool | last post by:
I want to see if this code works the way it should on a Big-Endian system. Also if anyone has any ideas on how determine this at compile-time so that I use the right decoding or encoding...
5
by: mohamed.alam78 | last post by:
Greetings, How does one find the format of a binary file to be in Little Endian or big Endian before we start reading the file. Thanks
9
by: Sheldon | last post by:
Hi, I am trying to make sense of this endian problem and so far, it is still Greek to me. I am have some files that have stored lat and lon data in binary format. The data was originally floats...
33
by: raghu | last post by:
Is it possible to know whether a system is little endian or big endian by writing a C program? If so, can anyone please give me the idea to approach... Thanks a ton. Regards, Raghu
17
by: Kelly B | last post by:
#include<stdio.h> #define LITTLE_ENDIAN 0 #define BIG_ENDIAN 1 int endian() { int i = 1; char *p = (char *)&i; if (p == 1)
23
by: Niranjan | last post by:
I have this program : void main() { int i=1; if((*(char*)&i)==1) printf("The machine is little endian."); else printf("The machine is big endian."); }
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.