BinaryWriter is writing Hex Backwards

Discussion in 'Programming & Scripting' started by mojobojo, Feb 24, 2009 with 14 replies and 852 views.

  1. mojobojo

    mojobojo Enthusiast

    Messages:
    694
    Ratings:
    96
    Code:
     
    bw.BaseStream.Position = 0xD217;
    bw.Write(long.Parse(textBox1.Text,System.Globalization.NumberStyles.HexNumber));
    
    This is what I am using, I dont know why its writing backwards.

     
  2. superaison

    superaison Banned

    Messages:
    1,404
    Ratings:
    269
    reverse the array maybe?

    If i'm not mistaken, something to do with big/little endian
     
  3. tOxiC x

    tOxiC x Member

    Messages:
    656
    Ratings:
    116
    What are you trying to accomplish? I use BinaryWriter a lot and never had to use the:

    bw.Write(long.Parse(textBox1.Text,System.Globalization.NumberStyles.HexNumber));

    Maybe we can get better code...
     
  4. superaison

    superaison Banned

    Messages:
    1,404
    Ratings:
    269
    try


    int writeint = Convert.ToInt32(textBox1.Text);

    bw.Write(writeint);

    idk.....
     
  5. zadesa

    zadesa Enthusiast

    Messages:
    75
    Ratings:
    43
    bw.Write(BitConverter.GetBytes(inthere)); ? lul i use that, works fine.
     
  6. Luxurious Meat

    Luxurious Meat Getting There

    Messages:
    615
    Ratings:
    120
    Is the field 'bw' a instance of the 'BinaryWriter' class or another custom class that inherits from it that was made to write in other another byte order?
     
  7. OP
    mojobojo

    mojobojo Enthusiast

    Messages:
    694
    Ratings:
    96
    You type hex into the box, and it writes the hex to the file.
     
  8. GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    the only other example of

    bw.Write(long.Parse(textBox1.Text,System.Globalization.NumberStyles.HexNumber));

    is used in a halo 2 modding programs and actually goes like this

    bw.Write(int.Parse(textBox1.Text, System.Globalization.NumberStyles.HexNumber));

    it could just be your hex editor, make sure its not set to big endian, but to little endian.
     
  9. OP
    mojobojo

    mojobojo Enthusiast

    Messages:
    694
    Ratings:
    96
    I will try that. Thanks

    Nope its still writing backwards, I even had it on little endian. I think.
     
  10. GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    dude you've been having lots of trouble with binary readers/writers. maybe its time to let the project go; just seems like your skill at programming isnt in a high enough range for this kind of stuff. Or talk to me on aim, give someone your source to edit. Do somthing, becuase without the background info, where helpless.
     
  11. OP
    mojobojo

    mojobojo Enthusiast

    Messages:
    694
    Ratings:
    96
    This has been the only Problem with this project. I know enough about Binary Writers to do what im doing. I learn the best when I can see examples, but Ive never seen source for a modding app, so Im going with what I know. I thank you guys for all of your help though, even though this hasnt helped much on this project you've helped me in learning C#.

    EDIT: Well it seems that my head is on backwards, because the int.Parse acually worked, But I was reading it in hex the wrong way. It had to do with the little endian setting. So Its my game that is reading it in big endian. Thanks GoldBl4d3 you helped me, I was just being the oblivios me I am.
     
  12. GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    so far if made the binarywriters flush before closing. What exactly do you want me to do with your source.

    Make it write in big endian or what are you looking for.
     
  13. OP
    mojobojo

    mojobojo Enthusiast

    Messages:
    694
    Ratings:
    96
    I would like it to write in big endian, If you could also add some commented text explaining what you did and what you added dose that would be nice. Thank you so much.
     
  14. GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    okay i will get it back to you hopfully some time today(friday 27th). and I know your still new alittle to c#. But you should think about code cleansing. Start grouping codes the go with eachother:

    //code
    //code

    //code

    //code
    //code
    //code

    next try to declare all of your variables at the top of the page, so it can easily be found(i already did that to your source). and make your code more manage able. I will give you a few sources to recent h2 modding programs just so you can see how to keeps managed code and maybe alittle on binaryReaders and writers
     
  15. OP
    mojobojo

    mojobojo Enthusiast

    Messages:
    694
    Ratings:
    96
    Thank you so much, I am forever greatfull. You are my hero!