473,387 Members | 1,891 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,387 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 4597
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."); }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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...

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.