“Konwertuj numer na sześciokątne js” Kod odpowiedzi

JavaScript przekształć numer na sześciokąt

hexString = yourNumber.toString(16);
Awesomered989

numer JS na hex

number = 255
h = parseInt(number, 10).toString(16)
// Result: "ff"

// Add Padding
h = h.padStart(6, "0")
// Result: "0000ff"
Powerful Puffin

JavaScript przekształć numer na sześciokąt

yourNumber = parseInt(hexString, 16);
Awesomered989

Konwertuj numer na sześciokątne js

/////////////////////////////////////////////////////////////////////////////
//  toHex().  Convert an ASCII string to hexadecimal.
/////////////////////////////////////////////////////////////////////////////
toHex(s)
{
    if (s.substr(0,2).toLowerCase() == "0x") {
        return s;
    }

    var l = "0123456789ABCDEF";
    var o = "";

    if (typeof s != "string") {
        s = s.toString();
    }
    for (var i=0; i<s.length; i++) {
        var c = s.charCodeAt(i);

        o = o + l.substr((c>>4),1) + l.substr((c & 0x0f),1);
    }

    return "0x" + o;
}
solly jay

Odpowiedzi podobne do “Konwertuj numer na sześciokątne js”

Pytania podobne do “Konwertuj numer na sześciokątne js”

Więcej pokrewnych odpowiedzi na “Konwertuj numer na sześciokątne js” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu