久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='PvkxW'></bdo><ul id='PvkxW'></ul>

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

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

  • <small id='PvkxW'></small><noframes id='PvkxW'>

      1. <tfoot id='PvkxW'></tfoot>

        如何將 Long 轉換為 byte[] 并返回到 java

        How do I convert Long to byte[] and back in java(如何將 Long 轉換為 byte[] 并返回到 java)
            <bdo id='aRiBr'></bdo><ul id='aRiBr'></ul>

              <tbody id='aRiBr'></tbody>

                1. <i id='aRiBr'><tr id='aRiBr'><dt id='aRiBr'><q id='aRiBr'><span id='aRiBr'><b id='aRiBr'><form id='aRiBr'><ins id='aRiBr'></ins><ul id='aRiBr'></ul><sub id='aRiBr'></sub></form><legend id='aRiBr'></legend><bdo id='aRiBr'><pre id='aRiBr'><center id='aRiBr'></center></pre></bdo></b><th id='aRiBr'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aRiBr'><tfoot id='aRiBr'></tfoot><dl id='aRiBr'><fieldset id='aRiBr'></fieldset></dl></div>

                2. <legend id='aRiBr'><style id='aRiBr'><dir id='aRiBr'><q id='aRiBr'></q></dir></style></legend>
                3. <small id='aRiBr'></small><noframes id='aRiBr'>

                  <tfoot id='aRiBr'></tfoot>
                  本文介紹了如何將 Long 轉換為 byte[] 并返回到 java的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  如何將 long 轉換為 byte[] 并返回 Java?

                  How do I convert a long to a byte[] and back in Java?

                  我正在嘗試將 long 轉換為 byte[] 以便能夠通過TCP 連接.另一方面,我想把那個 byte[] 轉換回 double.

                  I'm trying convert a long to a byte[] so that I will be able to send the byte[] over a TCP connection. On the other side I want to take that byte[] and convert it back into a double.

                  推薦答案

                  public byte[] longToBytes(long x) {
                      ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
                      buffer.putLong(x);
                      return buffer.array();
                  }
                  
                  public long bytesToLong(byte[] bytes) {
                      ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
                      buffer.put(bytes);
                      buffer.flip();//need flip 
                      return buffer.getLong();
                  }
                  

                  或者封裝在一個類中以避免重復創建ByteBuffers:

                  Or wrapped in a class to avoid repeatedly creating ByteBuffers:

                  public class ByteUtils {
                      private static ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);    
                  
                      public static byte[] longToBytes(long x) {
                          buffer.putLong(0, x);
                          return buffer.array();
                      }
                  
                      public static long bytesToLong(byte[] bytes) {
                          buffer.put(bytes, 0, bytes.length);
                          buffer.flip();//need flip 
                          return buffer.getLong();
                      }
                  }
                  

                  <小時>

                  由于它變得如此流行,我只想提一下,我認為在絕大多數情況下使用像 Guava 這樣的庫會更好.如果您對庫有一些奇怪的反對意見,您可能應該首先考慮 this answer 對于原生 java 解決方案.我認為我的回答真正要解決的主要問題是您不必自己擔心系統的字節序.


                  Since this is getting so popular, I just want to mention that I think you're better off using a library like Guava in the vast majority of cases. And if you have some strange opposition to libraries, you should probably consider this answer first for native java solutions. I think the main thing my answer really has going for it is that you don't have to worry about the endian-ness of the system yourself.

                  這篇關于如何將 Long 轉換為 byte[] 并返回到 java的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯誤)
                  Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語句 - 是“或/“和可能的?)
                  Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                  What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數的三元表達式的類型是什么?)
                  Read a text file and store every single character occurrence(讀取文本文件并存儲出現的每個字符)
                  Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉換 char 原語?)

                  1. <small id='G7vsH'></small><noframes id='G7vsH'>

                      <legend id='G7vsH'><style id='G7vsH'><dir id='G7vsH'><q id='G7vsH'></q></dir></style></legend>
                        <tbody id='G7vsH'></tbody>
                      <i id='G7vsH'><tr id='G7vsH'><dt id='G7vsH'><q id='G7vsH'><span id='G7vsH'><b id='G7vsH'><form id='G7vsH'><ins id='G7vsH'></ins><ul id='G7vsH'></ul><sub id='G7vsH'></sub></form><legend id='G7vsH'></legend><bdo id='G7vsH'><pre id='G7vsH'><center id='G7vsH'></center></pre></bdo></b><th id='G7vsH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='G7vsH'><tfoot id='G7vsH'></tfoot><dl id='G7vsH'><fieldset id='G7vsH'></fieldset></dl></div>

                        <tfoot id='G7vsH'></tfoot>
                            <bdo id='G7vsH'></bdo><ul id='G7vsH'></ul>
                          • 主站蜘蛛池模板: 欧美日韩一区在线 | 黄色免费av | 欧美中文字幕在线观看 | 亚洲精品一区二区三区蜜桃久 | 国产高清一区 | 国产精品久久久久久久久久久久 | 亚洲成人精选 | 欧美久久一级 | 欧美bondage紧缚视频 | 日韩成人av在线播放 | 欧美激情五月 | 亚洲精品电影网在线观看 | 久久尤物免费一区二区三区 | av午夜电影 | 毛片一区二区 | 欧美日韩三级 | 黄网站免费在线观看 | 玖玖操| 精品国产一区二区三区观看不卡 | 久久精品亚洲精品国产欧美 | 亚洲成人999 | 国产偷自视频区视频 | 成人在线观看免费观看 | 亚洲成人av一区二区 | 久久婷婷国产香蕉 | 精品美女视频在线观看免费软件 | 日本理论片好看理论片 | 久久一级 | 亚洲精品一区二区三区蜜桃久 | 国产综合精品一区二区三区 | 日韩视频中文字幕 | 国产精品二区三区 | 337p日本欧洲亚洲大胆精蜜臀 | 亚洲精品永久免费 | h视频在线观看免费 | 国产精品视频导航 | 精品国产一二三区 | 福利片在线观看 | 国产精品免费一区二区三区四区 | 亚洲综合电影 | 国产精品日韩欧美一区二区三区 |