Question: I have a register which reads out the version number in the following format. It is little endian. For example:

The register value read is `0x15000000` but I need to represent this in the GUI as `00.00.00_15`. 

How do I print in particular format with taking care of reversal as well in C#?

Answer: 
You could use the `BitConverter.GetBytes` to get an array of bytes..

```
int num = 0x15000000;
var bytes = BitConverter.GetBytes(num);

// If you want your code to run even on your Big Endian fridge,
// decomment this line :)
// if (!BitConverter.IsLittleEndian) Array.Reverse(bytes);

string str = string.Format("{0:x2}.{1:x2}.{2:x2}_{3:x2}", bytes[0], bytes[1], bytes[2], bytes[3]);

```

and then `string.Format("{num:x2}"` where `x2` will give an hex format of 2 digits

Note that in general, the `BitConverter.GetBytes` should be used only on Intel/AMD computers! If you want to make a generic code that can run anywhere, including your fridge, then it's better to use the next solution! (because your fridge could be Big Endian!)

Clearly you could do bit manipulation, shift `>>` and `&`

```
string str = string.Format("{0:x2}.{1:x2}.{2:x2}_{3:x2}", num & 0xFF, (num >> 8) & 0xFF, (num >> 16) & 0xFF, (num >> 24) & 0xFF);

```

But it's quite unreadable, unless you know a little of bit-manipulation :)
Most but not all [.net platforms are little endian](https://stackoverflow.com/questions/3685624/which-net-compatible-architectures-are-not-little-endian). Therefore the correct usage of [`BitConverter.GetBytes`](https://msdn.microsoft.com/en-us/library/de8fssa4(v=vs.110).aspx) is to not assume it will return one or the other.

```
int num = 0x15000000;
var bytes = BitConverter.GetBytes(num);
if (!BitConverter.IsLittleEndian) Array.Reverse(bytes); //it's big-endian, so reverse the bytes
string str = string.Format("{0:x2}.{1:x2}.{2:x2}_{3:x2}", bytes[0], bytes[1], bytes[2], bytes[3]);

```