【问题标题】:Convert int to bytes将 int 转换为字节
【发布时间】:2014-10-14 04:32:19
【问题描述】:

我有一个日历小部件,并通过捆绑将值传递给另一个活动。从捆绑包中获取值后,如何将“年”、“月”、“日”转换为字节?

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

【问题讨论】:

标签: android int byte


【解决方案1】:

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

byte[] bytes = ByteBuffer.allocate(4).putInt(year).array();

【讨论】:

    猜你喜欢
    • 2016-03-04
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 2011-09-04
    • 2017-12-21
    相关资源
    最近更新 更多