Converting a int to a BCD byte array

后端 未结 6 1745
感动是毒
感动是毒 2020-12-21 01:24

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.

6条回答
  •  自闭症患者
    2020-12-21 01:56

    static byte[] IntToBCD(int input) { 
        byte[] bcd = new byte[] { 
            (byte)(input>> 8), 
            (byte)(input& 0x00FF) 
        };
        return bcd;
    }
    

提交回复
热议问题