bitconverter

Writing a 2-byte integer to a stream?

I'm trying to interact with an application over the network which uses a simple protocol. I have to send a header that looks like this: 2 bytes = Data Length (including Request Type) 1 byte = Request Type I'm taking both parameters as integers: private static void WriteHeader(Stream buf, int length, int requestType) { buf.Write(Bi...

What is the Java equivalent of .NET BitConverter ?

I was writing an article in which I wanted to show how to send objects across the network, from Java to CLR/.Net and Back. http://ferozedaud.blogspot.com/2009/11/howto-serialize-data-from-object-from.html While doing research for this, I could not find a Java equivalent for BitConverter class that exists in .NET. Due to this, I had to ...

How to reverse a RectangleF to a Picasa face hash.

Here are the details for what Picasa stores as a hash. It stores them like this: faces=rect64(54391dc9b6a76c2b),4cd643f64b715489 [DSC_2289.jpg] faces=rect64(1680000a5c26c82),76bc8d8d518750bc Info on the web says this: The number encased in rect64() is a 64-bit hexadecimal number. Break that up into four 16-bit numbers. Divide each ...

Is there a less painful way to GetBytes for a buffer not starting at 0?

I am having to deal with raw bytes in a project and I need to basically do something like this byte[] ToBytes(){ byte[] buffer=new byte[somelength]; byte[] tmp; tmp=BitConverter.GetBytes(SomeShort); buffer[0]=tmp[0]; buffer[1]=tmp[1]; tmp=BitConverter.GetBytes(SomeOtherShort); buffer[2]=tmp[0]; buffer[3]=tmp[1]; } I fe...

Alternative to BitConverter.ToInt32

I'm using BitConverter.ToInt32 to pack 3 byte values into an int, like so: byte R = 0; byte G = 0; byte B = 0; int i = BitConverter.ToInt32(new byte[] { R, G, B, 0 }, 0); Is there a faster way to do this that doesn't involve the creation of a new int each time? Getting the bytes out of an int is easy: int i = 34234; byte B = (byte)(...

C# Breakpoint Weirdness

In my program I've got two data files A and B. The data in A is static and the data in B refers back to the data in A. In order to make sure the data in B is invalidated when A is changed, I keep an identifier for each of the links which is a long byte-string identifying the data. I get this string using BitConverter on some of the impor...

Bit convector : Get byte array from string

When I have a string like "0xd8 0xff 0xe0" I do Text.Split(' ').Select(part => byte.Parse(part, System.Globalization.NumberStyles.HexNumber)).ToArray(); But if I got string like "0xd8ffe0" I don't know what to do ? also I'm able for recommendations how to write byte array as one string. ...

Index out of range at "int msgLength = BitConverter.ToInt32(gzBuffer, 0);"

Hello, I am currently working on some game made in C# XNA. Since I need to send a huge chunk of data over net (bout 96kb), I am using some string compressor/decompressor code, which I found on the internet. The code looks like this: public static string Compress(string text) { byte[] buffer = Encoding.UTF8.GetBytes(...

how to get ushort data in c# A909 for 41104 ??

hello I'm trying to convert an int value to 16 bit unsigned char type (USHORT) in example 41104 is A909 in ushort but in c# i tried code samples as byte[] bytes = BitConverter.GetBytes(41104); string bytes = BitConverter.ToString(byteArray); //it reurns "90-A0" (with the http://msdn.microsoft.com/tr-tr/library/8wwsdz3k.aspx msnd hel...

help with BitConverter!

I cannot get the BitConverter class to work. I get the error 'BitConverter' undeclared (first use this function). I have tried putting 'using System;' at the top of my code because I saw that in some examples online, but it then tells me that 'System' has not been declared. What am i missing? A #include file? ...