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

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

    3. <small id='X0HLP'></small><noframes id='X0HLP'>

    4. Java中的十六進制轉整數

      Hexadecimal to Integer in Java(Java中的十六進制轉整數)

    5. <small id='RtjvT'></small><noframes id='RtjvT'>

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

            <tbody id='RtjvT'></tbody>
          • <legend id='RtjvT'><style id='RtjvT'><dir id='RtjvT'><q id='RtjvT'></q></dir></style></legend>

              <tfoot id='RtjvT'></tfoot>

                <bdo id='RtjvT'></bdo><ul id='RtjvT'></ul>
                本文介紹了Java中的十六進制轉整數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試將十六進制字符串轉換為整數.字符串十六進制是從散列函數 (sha-1) 計算出來的.我收到此錯誤:java.lang.NumberFormatException.我猜它不喜歡十六進制的字符串表示.我怎樣才能做到這一點.這是我的代碼:

                I am trying to convert a String hexadecimal to an integer. The string hexadecimal was calculated from a hash function (sha-1). I get this error : java.lang.NumberFormatException. I guess it doesn't like the String representation of the hexadecimal. How can I achieve that. Here is my code :

                public Integer calculateHash(String uuid) {
                
                    try {
                        MessageDigest digest = MessageDigest.getInstance("SHA1");
                        digest.update(uuid.getBytes());
                        byte[] output = digest.digest();
                
                        String hex = hexToString(output);
                        Integer i = Integer.parseInt(hex,16);
                        return i;           
                
                    } catch (NoSuchAlgorithmException e) {
                        System.out.println("SHA1 not implemented in this system");
                    }
                
                    return null;
                }   
                
                private String hexToString(byte[] output) {
                    char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                            'A', 'B', 'C', 'D', 'E', 'F' };
                    StringBuffer buf = new StringBuffer();
                    for (int j = 0; j < output.length; j++) {
                        buf.append(hexDigit[(output[j] >> 4) & 0x0f]);
                        buf.append(hexDigit[output[j] & 0x0f]);
                    }
                    return buf.toString();
                
                }
                

                例如,當我傳遞這個字符串時:_DTOWsHJbEeC6VuzWPawcLA,他的哈希值是:0xC934E5D372B2AB6D0A50B9F0341A00ED029BDC15

                For example, when I pass this string : _DTOWsHJbEeC6VuzWPawcLA, his hash his : 0xC934E5D372B2AB6D0A50B9F0341A00ED029BDC15

                但我得到:java.lang.NumberFormatException:對于輸入字符串:0xC934E5D372B2AB6D0A50B9F0341A00ED029BDC15"

                But i get : java.lang.NumberFormatException: For input string: "0xC934E5D372B2AB6D0A50B9F0341A00ED029BDC15"

                我真的需要這樣做.我有一組由它們的 UUID 標識的元素,它們是字符串.我將不得不存儲這些元素,但我的限制是使用整數作為它們的 id.這就是為什么我計算給定參數的哈希值,然后將其轉換為 int.也許我做錯了,但有人可以給我一個建議來正確地實現它!

                I really need to do this. I have a collection of elements identified by their UUID which are string. I will have to store those elements but my restrictions is to use an integer as their id. It is why I calculate the hash of the parameter given and then I convert to an int. Maybe I am doing this wrong but can someone gives me an advice to achieve that correctly!!

                感謝您的幫助!!

                推薦答案

                為什么不使用 java 功能呢:

                Why do you not use the java functionality for that:

                如果您的數字很小(比您的小),您可以使用:Integer.parseInt(hex, 16) 將十六進制 - 字符串轉換為整數.

                If your numbers are small (smaller than yours) you could use: Integer.parseInt(hex, 16) to convert a Hex - String into an integer.

                  String hex = "ff"
                  int value = Integer.parseInt(hex, 16);  
                

                對于像你這樣的大數字,使用 public BigInteger(String val, int radix)

                For big numbers like yours, use public BigInteger(String val, int radix)

                  BigInteger value = new BigInteger(hex, 16);
                

                @見JavaDoc:

                • Integer.parseInt(String value, int radix)
                • BigInteger(String value, int radix)

                這篇關于Java中的十六進制轉整數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                How to convert Integer to int?(如何將整數轉換為整數?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

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

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

                      <tfoot id='QpzCd'></tfoot>

                      • <bdo id='QpzCd'></bdo><ul id='QpzCd'></ul>
                          主站蜘蛛池模板: 国产精品久久久久久久久免费桃花 | 久久久激情视频 | 日本天天操 | 91看片网| 亚洲精品国产一区 | 久久五月婷| 欧美二级 | 久久大陆 | 九色视频网站 | 91精品国产91久久久久久吃药 | 日韩欧美操| 国产999精品久久久 精品三级在线观看 | 国产欧美精品在线观看 | 欧美精品在线免费观看 | 黄色毛片在线播放 | 亚洲 欧美 综合 | 亚洲 欧美 另类 综合 偷拍 | 天天射天天干 | 国产欧美在线观看 | 欧美黄色片 | 国产精品毛片无码 | 日韩中文一区二区三区 | 激情a| 天天综合网天天综合色 | a级毛片基地 | 亚洲国产看片 | 亚洲视频在线观看 | 国产欧美一区二区三区日本久久久 | 国产一区二区三区四区在线观看 | 久久伦理电影 | 99精品一区 | 日本网站免费观看 | 桃花av在线 | 欧美性一级 | 精品一区二区三区中文字幕 | 91资源在线| 国产精品成人品 | 在线观看www | 成人免费观看男女羞羞视频 | 自拍偷拍亚洲欧美 | 精品视频在线免费观看 |