<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Kotlin 程序:將字節數組轉換為十六進制 > 原文: [https://www.programiz.com/kotlin-programming/examples/convert-byte-array-hexadecimal](https://www.programiz.com/kotlin-programming/examples/convert-byte-array-hexadecimal) #### 在此程序中,您將學習在 Kotlin 中將字節數組轉換為十六進制的不同技術。 ## 示例 1:將字節數組轉換為十六進制值 ```kt fun main(args: Array<String>) { val bytes = byteArrayOf(10, 2, 15, 11) for (b in bytes) { val st = String.format("%02X", b) print(st) } } ``` 運行該程序時,輸出為: ```kt 0A020F0B ``` 在上面的程序中,我們有一個名為`bytes`的字節數組。 要將字節數組轉換為十六進制值,我們遍歷數組中的每個字節,并使用`String`的`format()`。 我們使用`%02X`打印十六進制(`X`)值的兩個位置(`02`)并將其存儲在字符串`st`中。 對于大字節數組轉換,這是相對較慢的過程。 我們可以使用下面顯示的字節操作大大提高執行速度。 * * * ## 示例 2:使用字節操作將字節數組轉換為十六進制值 ```kt import kotlin.experimental.and private val hexArray = "0123456789ABCDEF".toCharArray() fun bytesToHex(bytes: ByteArray): String { val hexChars = CharArray(bytes.size * 2) for (j in bytes.indices) { val v = (bytes[j] and 0xFF.toByte()).toInt() hexChars[j * 2] = hexArray[v ushr 4] hexChars[j * 2 + 1] = hexArray[v and 0x0F] } return String(hexChars) } fun main(args: Array<String>) { val bytes = byteArrayOf(10, 2, 15, 11) val s = bytesToHex(bytes) println(s) } ``` 該程序的輸出與示例 1 相同。 以下是等效的 Java 代碼: [Java 程序:將字節數組轉換為十六進制](/java-programming/examples/convert-byte-array-hexadecimal "Java program to convert byte array to hexadecimal")。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看