Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Conversion from BigEndian to Little Endia

Conversion from BigEndian to Little Endia

Scheduled Pinned Locked Moved C#
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hpetriffer
    wrote on last edited by
    #1

    Is there a class available to convert data from Little to BigEndian? Regards Hansjörg

    D S 2 Replies Last reply
    0
    • H hpetriffer

      Is there a class available to convert data from Little to BigEndian? Regards Hansjörg

      D Offline
      D Offline
      Divyang Mithaiwala
      wrote on last edited by
      #2

      If you found usefull. See this.


      Divyang Mithaiwala System Engineer & Software Developer

      H 1 Reply Last reply
      0
      • D Divyang Mithaiwala

        If you found usefull. See this.


        Divyang Mithaiwala System Engineer & Software Developer

        H Offline
        H Offline
        hpetriffer
        wrote on last edited by
        #3

        I need something to convert a byte array (which contains int, int64...) from big to little endian. I don't see any possibitlity to use this class, isn't it? Thanks for your help! Regards Hansjörg

        1 Reply Last reply
        0
        • H hpetriffer

          Is there a class available to convert data from Little to BigEndian? Regards Hansjörg

          S Offline
          S Offline
          Steve Hansen
          wrote on last edited by
          #4

          Best way is to write some methods yourself, what types do you have to convert? public static int ReverseEndian(int x) { return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)>>8) | (x>>24)); } public static uint ReverseEndian(uint x) { return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)>>8) | (x>>24)); } ...

          H 1 Reply Last reply
          0
          • S Steve Hansen

            Best way is to write some methods yourself, what types do you have to convert? public static int ReverseEndian(int x) { return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)>>8) | (x>>24)); } public static uint ReverseEndian(uint x) { return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)>>8) | (x>>24)); } ...

            H Offline
            H Offline
            hpetriffer
            wrote on last edited by
            #5

            I have to convert all standard types... I hoped that something is available Thanks for your help!

            S 1 Reply Last reply
            0
            • H hpetriffer

              I have to convert all standard types... I hoped that something is available Thanks for your help!

              S Offline
              S Offline
              Steve Hansen
              wrote on last edited by
              #6

              I don't know of any implementation that does it, the code I gave was from a program of mine where I also did everything myself. If you have to convert all standard types I would create your own BinaryReader which takes the default BinaryReader as parameter and endian swap each method before passing back. using System.IO; public class EndianReader : BinaryReader { #region Constructors public EndianReader(Stream stream) : base(stream) { } #endregion #region Methods public override int ReadInt32() { return ReverseEndian(base.ReadInt32()); } #endregion #region Class Methods public static int ReverseEndian(int x) { return ((x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24)); } #endregion }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups