Javascript dec十六进制

时间:2016-05-04 12:12:17

标签: javascript hex decimal

var dec = prompt("Enter a number");

if (dec != null && dec > 0) {
	var hex = dec.toString(16);
	alert(hex);
}
else {
	alert("number must be greater than 0");
}

我有以下代码 当我在提示中输入一个数字时,它会提醒相同的号码 示例:我输入256 提醒:256

2 个答案:

答案 0 :(得分:2)

#include <iostream> #include <vector> using namespace std; union my_union { string str; int a; }; int main() { vector<my_union> v; my_union u; // error: use of deleted function 'my_union::~my_union()' u.str = "foo"; v.push_back(u); return 0; } 将返回prompt。只需先将其转换为普通string

number

答案 1 :(得分:1)

试试这个

var dec = prompt("Enter a number");

if (dec != null && dec > 0) {
    var hex = parseInt(dec,16);
    alert(hex);
}
else {
    alert("number must be greater than 0");
}