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 :)
Don't treat it as a number - it's not a number. The fact that you can efficiently store it as a single `int` is irrelevant - just an implementation detail.

Once you start thinking in bytes in an array, you find that "little-endian" is not really anything important. Instead, you just have a structure that starts with one byte meaning one thing, the next one something else...

There's many ways to get to that behaviour, depending on where you get the actual value - taking an `int` will not give you control over endianness, for example. If you just take a `byte[]`, you can do something like this:

```
string.Format("{0}.{1}.{2}_{3}", data[3], data[2], data[1], data[0])

```

This is usually very easy to handle when you're working with e.g. loading data from a file, or sending it over a socket. If you're dealing with native code interop, you can use a structure instead of `int` (or similar):

```
struct MyVersionNumber
{
  byte Lowest;
  byte Other;
  byte YetAnother;
  byte Highest;
}

```

Think in types - don't use primitives unless what you have *is a primitive value*. You're obviously working with a composite value that's (for whatever reason) folded into a primitive type. That's not a good idea for maintaining complexity :) 

Once you have type, you can ensure proper type safety, validation, and just override the `ToString` method, for example, to output the value for the user.