日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JavaScript | 将十进制转换为十六进制,反之亦然

發布時間:2025/3/11 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JavaScript | 将十进制转换为十六进制,反之亦然 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Sometimes we need to convert an integer value which is in decimal format to the hexadecimal string in JavaScript or need a decimal value from a given hexadecimal string.

有時,我們需要將十進制格式的整數值轉換為JavaScript中的十六進制字符串,或者需要給定十六進制字符串中的十進制值 。

Read more: How to assign decimal, octal and hexadecimal values to the variables in JavaScript?

: 如何為JavaScript中的變量分配十進制,八進制和十六進制值?

In such cases, we can convert a decimal value to the hexadecimal string by using the number.toString(16) and hexadecimal string to the decimal by using hex_string.parseInt(16).

在這種情況下,我們可以通過使用number.toString(16)和十六進制字符串到十進制通過使用hex_string.parseInt(16) 轉換成十進制值以十六進制字符串 。

In both cases, 16 is the base to the number system that says that target or source value format is hexadecimal.

在這兩種情況下,16是基座到數字系統 ,指出目標或源值格式是十六進制。

Example:

例:

<html> <head> <title>JavaScipt Example</title> </head><body><script> var a = 10;var b = 12345;document.write("a = " + a.toString(16) + "<br>");document.write("b = " + b.toString(16) + "<br>");//conver hexadecimal string to the int againvar hex = "0A"; //hex of 10var dec = parseInt(hex,16);document.write("dec = " + dec + "<br>");</script> </body> </html>

Output

輸出量

a = a b = 3039 dec = 10

翻譯自: https://www.includehelp.com/code-snippets/convert-decimal-to-hexadecimal-and-vice-versa-in-javascript.aspx

總結

以上是生活随笔為你收集整理的JavaScript | 将十进制转换为十六进制,反之亦然的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。