View Single Post
Old 07-07-2007, 09:43 PM   #6 (permalink)
Ohms_Law
Forum Expert
 
Ohms_Law's Avatar
 
Join Date: Sep 2004
Age: 37
Posts: 1,006
Default

Yea, I kind of figured that out last night...


It's been a long time since I've messed around with endian'ness. What a PITA. It took me forever to figure out that that's what the problem was, and I honestly didn't know for sure until I just read your reply. damnit... now I really understand what you were saying about about the overflow check problems.

I'm going to mess around with it some still, just for the heck of it. Thanks for the replies at least, I appreciate it.


edit: in case anyone else is interested (I'm certain that Zippy know this...) here's a little example of the problem that BitConverter causes.

Example program:
Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace BitConverter_test
{
    class Program
    {
        static void Main(string[] args)
        {
            int integerTest = 123456;
            byte[] bytearrTest1 = new byte[4];
            byte[] bytearrTest2 = new byte[4];

            bytearrTest1[0] = (byte)(integerTest >> 24);
            bytearrTest1[1] = (byte)(integerTest >> 16);
            bytearrTest1[2] = (byte)(integerTest >> 8);
            bytearrTest1[3] = (byte)integerTest;

            bytearrTest2 = BitConverter.GetBytes(integerTest);

            Console.WriteLine("Byte array 1");
            Console.WriteLine(bytearrTest1[0].ToString());
            Console.WriteLine(bytearrTest1[1].ToString());
            Console.WriteLine(bytearrTest1[2].ToString());
            Console.WriteLine(bytearrTest1[3].ToString());

            Console.WriteLine("Byte Array 2");
            Console.WriteLine(bytearrTest2[0].ToString());
            Console.WriteLine(bytearrTest2[1].ToString());
            Console.WriteLine(bytearrTest2[2].ToString());
            Console.WriteLine(bytearrTest2[3].ToString());

            Console.WriteLine("Integer");
            Console.WriteLine(integerTest.ToString());
            Console.ReadLine();
        }
    }
}
output:2007-07-07_175443.jpg

notice how the two Byte arrays are mirrors of each other.

Last edited by Ohms_Law; 07-07-2007 at 09:57 PM.
Ohms_Law is offline   Reply With Quote