You need to convert integer variable or constant to byte array ( [] byte ). How to do that?

Solution :

UPDATE: The answer below demonstrates few methods of converting integer variable to []byte (byte array/slice). The second method should be the answer that you ought to use. Other methods can be useful as well depending on your requirement.

By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.