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

  1. <legend id='vLslB'><style id='vLslB'><dir id='vLslB'><q id='vLslB'></q></dir></style></legend>
  2. <tfoot id='vLslB'></tfoot>
    • <bdo id='vLslB'></bdo><ul id='vLslB'></ul>

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

    1. <i id='vLslB'><tr id='vLslB'><dt id='vLslB'><q id='vLslB'><span id='vLslB'><b id='vLslB'><form id='vLslB'><ins id='vLslB'></ins><ul id='vLslB'></ul><sub id='vLslB'></sub></form><legend id='vLslB'></legend><bdo id='vLslB'><pre id='vLslB'><center id='vLslB'></center></pre></bdo></b><th id='vLslB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vLslB'><tfoot id='vLslB'></tfoot><dl id='vLslB'><fieldset id='vLslB'></fieldset></dl></div>
    2. 將 IPv6 轉換為 long 并將 long 轉換為 IPv6

      Conversion IPv6 to long and long to IPv6(將 IPv6 轉換為 long 并將 long 轉換為 IPv6)

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

              <tfoot id='9nvh6'></tfoot>

                <small id='9nvh6'></small><noframes id='9nvh6'>

                本文介紹了將 IPv6 轉換為 long 并將 long 轉換為 IPv6的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我應該如何執行從 IPv6 到 long 的轉換,反之亦然?

                How should I perform conversion from IPv6 to long and vice versa?

                到目前為止我有:

                    public static long IPToLong(String addr) {
                            String[] addrArray = addr.split("\.");
                            long num = 0;
                            for (int i = 0; i < addrArray.length; i++) {
                                    int power = 3 - i;
                
                                    num += ((Integer.parseInt(addrArray[i], 16) % 256 * Math.pow(256, power)));
                            }
                            return num;
                    }
                
                    public static String longToIP(long ip) {
                            return ((ip >> 24) & 0xFF) + "."
                                    + ((ip >> 16) & 0xFF) + "."
                                    + ((ip >> 8) & 0xFF) + "."
                                    + (ip & 0xFF);
                
                    }
                

                這是正確的解決方案還是我錯過了什么?

                Is it correct solution or I missed something?

                (如果解決方案對 ipv4 和 ipv6 都有效,那就完美了)

                (It would be perfect if the solution worked for both ipv4 and ipv6)

                推薦答案

                IPv6 地址是一個 128 位數字,如所述 這里.Java 中的 long 以 64 位表示,因此您需要另一種結構,例如 BigDecimal 或兩個 long(一個包含兩個 long 數組的容器,或者只是一個包含兩個 long 數組的容器)來存儲 IPv6 地址.

                An IPv6 address is a 128-bit number as described here. A long in Java is represented on 64 bits, so you need another structure, like a BigDecimal or two longs (a container with an array of two longs or simply an array of two longs) in order to store an IPv6 address.

                下面是一個例子(只是給你一個想法):

                Below is an example (just to provide you an idea):

                public class Asd {
                
                    public static long[] IPToLong(String addr) {
                        String[] addrArray = addr.split(":");//a IPv6 adress is of form 2607:f0d0:1002:0051:0000:0000:0000:0004
                        long[] num = new long[addrArray.length];
                        
                        for (int i=0; i<addrArray.length; i++) {
                            num[i] = Long.parseLong(addrArray[i], 16);
                        }
                        long long1 = num[0];
                        for (int i=1;i<4;i++) {
                            long1 = (long1<<16) + num[i];
                        }
                        long long2 = num[4];
                        for (int i=5;i<8;i++) {
                            long2 = (long2<<16) + num[i];
                        }
                        
                        long[] longs = {long2, long1};
                        return longs;
                    }
                    
                    
                    public static String longToIP(long[] ip) {
                        String ipString = "";
                        for (long crtLong : ip) {//for every long: it should be two of them
                
                            for (int i=0; i<4; i++) {//we display in total 4 parts for every long
                                ipString = Long.toHexString(crtLong & 0xFFFF) + ":" + ipString;
                                crtLong = crtLong >> 16;
                            }
                        }
                        return ipString;
                    
                    }
                    
                    static public void main(String[] args) {
                        String ipString = "2607:f0d0:1002:0051:0000:0000:0000:0004";
                        long[] asd = IPToLong(ipString);
                        
                        System.out.println(longToIP(asd));
                    }
                }
                

                這篇關于將 IPv6 轉換為 long 并將 long 轉換為 IPv6的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 原語?)
                  <legend id='oT7O0'><style id='oT7O0'><dir id='oT7O0'><q id='oT7O0'></q></dir></style></legend>
                    <bdo id='oT7O0'></bdo><ul id='oT7O0'></ul>

                  • <tfoot id='oT7O0'></tfoot>

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

                    1. <i id='oT7O0'><tr id='oT7O0'><dt id='oT7O0'><q id='oT7O0'><span id='oT7O0'><b id='oT7O0'><form id='oT7O0'><ins id='oT7O0'></ins><ul id='oT7O0'></ul><sub id='oT7O0'></sub></form><legend id='oT7O0'></legend><bdo id='oT7O0'><pre id='oT7O0'><center id='oT7O0'></center></pre></bdo></b><th id='oT7O0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oT7O0'><tfoot id='oT7O0'></tfoot><dl id='oT7O0'><fieldset id='oT7O0'></fieldset></dl></div>
                            <tbody id='oT7O0'></tbody>
                        • 主站蜘蛛池模板: 午夜色播| 91手机精品视频 | 亚洲久草 | 国产精品国产a级 | 人人做人人澡人人爽欧美 | 99久久夜色精品国产亚洲96 | 色在线视频网站 | 亚洲字幕在线观看 | 视频一区在线观看 | 日韩中出| 亚洲成人av | 中文字幕免费视频 | 亚洲视频在线一区 | 日韩一级黄色毛片 | 久草视频观看 | 国产毛片毛片 | 欧美精品一区二区三区在线 | 国产一区二区中文字幕 | 色毛片 | 午夜影院免费体验区 | 三级成人在线 | 国产精品欧美一区二区三区不卡 | 欧美日韩亚洲一区 | 淫片一级国产 | 九九久久久| www亚洲成人 | 女同久久 | 亚洲欧美国产一区二区三区 | 久久av一区二区三区 | 岛国av免费看| 亚洲精品国产一区 | 亚洲精品视频三区 | 嫩草懂你的影院入口 | 成人欧美一区二区三区在线观看 | 欧美国产日韩在线 | 成人午夜影院 | 久草新在线 | 欧美伊人久久久久久久久影院 | 国产高清久久久 | 国产成人免费视频 | 久久精品超碰 |