Java:如何使用大于0x7F的字节文字 [英] Java: How to use byte literals greater than 0x7F

查看:342
本文介绍了Java:如何使用大于0x7F的字节文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我不能采用无符号字节的字节数组(来自诸如Wire Shark之​​类的东西)并将其放入Java中....因为会处理任何大于127十进制/0x07F的值,所以我会得到编译错误不是作为字节,而是作为整数....IE:

In Java, I can't take a byte array of unsigned bytes (from something such as Wire Shark) and put this into java.... Because I will get compile errors since anything greater than 127 decimal/0x07F is treated not as a byte, but as an int.... IE:

        byte[] protocol = { 0x04, 0x01, 0x00, 0x50, /*error*/0xc1, /*error*/0xdb, 0x1c, /*error*/0x8c, 
                0x4d, 0x4f, 0x5a, 0x00 };

需要一种处理无符号char数组并将其作为文字放入Java的好方法.

Need a good way to handle taking unsigned char arrays and putting them into Java as literals.

推荐答案

将其投射为(字节).

这篇关于Java:如何使用大于0x7F的字节文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆