简体   繁体   English

Java / Android-如何将int数组转换为最小字节数组?

[英]Java / Android - How to convert int array into smallest byte array?

I need to convert an int array like this... 我需要像这样转换一个int数组...

int[] myInts = {
    99999,
    9999,
    99999,
    1,
    1234567890,
    24385933,
    99
};

...as efficiently as possible into a byte[] so it can be saved on an NFC tag. ...尽可能高效地保存到byte[]以便可以将其保存在NFC标签中。

I have seen this very similar question from which I have tried the two the answers ( here and here ), but the byte arrays they create both have a length of 28. 我看到了一个非常相似的问题 ,从中我尝试了两个答案( 在这里这里 ),但是它们创建的字节数组的长度均为28。

Unfortunately, that's no good for me as I need to create a byte[] with a maximum length of 16 (as the tag this data has to be saved on is a MIFARE Ultralight EV1). 不幸的是,这对我没有好处,因为我需要创建一个最大长度为16的byte [] (因为此数据必须保存的标签是MIFARE Ultralight EV1)。

Is there any other approach I could try in order to convert myInts to a byte[16] ? 我可以尝试将myInts转换为byte[16]其他方法吗?

Apologies. 道歉。 I got some info wrong in my question as according to the MIFARE Ultralight EV1 datasheet , the tag can hold 48 bytes of user data - which is good news. 根据MIFARE Ultralight EV1数据表 ,我在问题中得到了一些错误信息,该标签可以容纳48个字节的用户数据-这是个好消息。 (I had been a bit mislead by NXP's example app which is hardcoded to just use 16 bytes.) (我被恩智浦的示例应用程序误导了一点,该应用程序硬编码为仅使用16个字节。)

Thank you for the helpful comments anyway. 无论如何,谢谢您的有用评论。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM