1. <tfoot id='3Xeaz'></tfoot>

        • <bdo id='3Xeaz'></bdo><ul id='3Xeaz'></ul>
        <legend id='3Xeaz'><style id='3Xeaz'><dir id='3Xeaz'><q id='3Xeaz'></q></dir></style></legend>
        <i id='3Xeaz'><tr id='3Xeaz'><dt id='3Xeaz'><q id='3Xeaz'><span id='3Xeaz'><b id='3Xeaz'><form id='3Xeaz'><ins id='3Xeaz'></ins><ul id='3Xeaz'></ul><sub id='3Xeaz'></sub></form><legend id='3Xeaz'></legend><bdo id='3Xeaz'><pre id='3Xeaz'><center id='3Xeaz'></center></pre></bdo></b><th id='3Xeaz'></th></span></q></dt></tr></i><div id='3Xeaz'><tfoot id='3Xeaz'></tfoot><dl id='3Xeaz'><fieldset id='3Xeaz'></fieldset></dl></div>

        <small id='3Xeaz'></small><noframes id='3Xeaz'>

        2字节短java

        时间:2023-07-27
        • <legend id='iptI1'><style id='iptI1'><dir id='iptI1'><q id='iptI1'></q></dir></style></legend>
            <bdo id='iptI1'></bdo><ul id='iptI1'></ul>
            <tfoot id='iptI1'></tfoot>

                <tbody id='iptI1'></tbody>
            1. <small id='iptI1'></small><noframes id='iptI1'>

              1. <i id='iptI1'><tr id='iptI1'><dt id='iptI1'><q id='iptI1'><span id='iptI1'><b id='iptI1'><form id='iptI1'><ins id='iptI1'></ins><ul id='iptI1'></ul><sub id='iptI1'></sub></form><legend id='iptI1'></legend><bdo id='iptI1'><pre id='iptI1'><center id='iptI1'></center></pre></bdo></b><th id='iptI1'></th></span></q></dt></tr></i><div id='iptI1'><tfoot id='iptI1'></tfoot><dl id='iptI1'><fieldset id='iptI1'></fieldset></dl></div>
                • 本文介绍了2字节短java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在从串行端口读取 133 个长度的数据包,最后 2 个字节包含 CRC 值,2 个字节值我使用 java 制作单个(我认为是短的).这就是我所做的,

                  i'm reading 133 length packet from serialport,last 2 bytes contain CRC values,2 bytes value i've make single(short i think) using java. this what i have done,

                  short high=(-48 & 0x00ff);
                  short low=80;
                  
                  short c=(short) ((high<<8)+low);
                  

                  但我没有得到正确的结果,是因为签名值有问题吗?我该如何解决这个问题,请帮助我遇到麻烦

                  but i'm not getting correct result,is it problem because signed valued? how can i solve this problem,plz help me i'm in trouble

                  推荐答案

                  请记住,如果您对细节不太熟悉,则不必为位移而纠结.您可以使用 ByteBuffer 来帮助您:

                  Remember, you don't have to tie yourself in knots with bit shifting if you're not too familiar with the details. You can use a ByteBuffer to help you out:

                  ByteBuffer bb = ByteBuffer.allocate(2);
                  bb.order(ByteOrder.LITTLE_ENDIAN);
                  bb.put(firstByte);
                  bb.put(secondByte);
                  short shortVal = bb.getShort(0);
                  

                  反之亦然,你可以先放一个短,然后再拉出字节.

                  And vice versa, you can put a short, then pull out bytes.

                  顺便说一下,按位运算会自动将操作数提升到至少一个 int 的宽度.真的没有不允许将一个字节移动超过 7 位"的概念以及其他似乎正在流传的谣言.

                  By the way, bitwise operations automatically promote the operands to at least the width of an int. There's really no notion of "not being allowed to shift a byte more than 7 bits" and other rumours that seem to be going round.

                  这篇关于2字节短java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将 .txt 文件转换为 Hadoop 的序列文件格式 下一篇:Java:为什么我会收到错误消息“类型不匹配:无法

                  相关文章

                  最新文章

                  <small id='RPiIU'></small><noframes id='RPiIU'>

                • <i id='RPiIU'><tr id='RPiIU'><dt id='RPiIU'><q id='RPiIU'><span id='RPiIU'><b id='RPiIU'><form id='RPiIU'><ins id='RPiIU'></ins><ul id='RPiIU'></ul><sub id='RPiIU'></sub></form><legend id='RPiIU'></legend><bdo id='RPiIU'><pre id='RPiIU'><center id='RPiIU'></center></pre></bdo></b><th id='RPiIU'></th></span></q></dt></tr></i><div id='RPiIU'><tfoot id='RPiIU'></tfoot><dl id='RPiIU'><fieldset id='RPiIU'></fieldset></dl></div>

                  <legend id='RPiIU'><style id='RPiIU'><dir id='RPiIU'><q id='RPiIU'></q></dir></style></legend>

                  1. <tfoot id='RPiIU'></tfoot>
                    • <bdo id='RPiIU'></bdo><ul id='RPiIU'></ul>