将int转换为字节

时间:2014-10-14 04:32:20

标签: android int byte

我有一个日历小部件,并通过bundle将值传递给另一个活动。从bundle获取值后,如何将“year”,“month”,“day”转换为字节?

    int year = extras.getInt("year");
    int day = extras.getInt("day");
    int month = extras.getInt("month");

1 个答案:

答案 0 :(得分:1)

您可以使用ByteBuffer将int转换为字节。

byte[] bytes = ByteBuffer.allocate(4).putInt(year).array();
相关问题