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.