Converting an Int to a BCD byte array

Kingpin picture Kingpin · Aug 18, 2011 · Viewed 8.2k times · Source

I want to convert an int to a byte[2] array using BCD.

The int in question will come from DateTime representing the Year and must be converted to two bytes.

Is there any pre-made function that does this or can you give me a simple way of doing this?

example:

int year = 2010

would output:

byte[2]{0x20, 0x10};

Answer