I have Hex string like 1480D604. Which I need to change order from Low to High 0x04D68014 and then I need to cast it into decimal value. One approach that I can think is first change their order first like.
Step 1 : 14-80-D6-04 --> 04-D6-80-14
How can I change this order from Low to High order in hex value.
Cast output from first step into decimal value like this
int decValue = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
Is there any simple way to achieve this in single step.
Best How To :
The only way to do it in a "single step" is to define a method, use the
public static int ReverseByteOrder(int value)
byte bytes = BitConverter.GetBytes(value);
return BitConverter.ToInt32(bytes, 0);
int value = 0x1480D604; //or parse from string
int decValue = ReverseByteOrder(value);
//decValue = 0x04D68014
Strictly speaking, you should look at
BitConverter.IsLittleEndian as it is possible that the order is already in the correct order, depending on the system it's running on.
This is very unlikely, so I wouldn't bother coding to that case, but I would at the very least cause the program to fall over if run on a system where
BitConverter.IsLittleEndian is not