Как преобразовать числа между шестнадцатеричным и десятичным

Вы можете проверить событие загрузки iframe

onLoad="alert(this.contentWindow.location);"

или на jquery:

$('iframe#yourId').load(function() {
  alert("the iframe has been loaded");
});
139
задан Micha Wiedenmann 10 December 2018 в 09:52
поделиться

6 ответов

Для преобразования из десятичного числа для преобразовывания в шестнадцатеричную систему делают...

string hexValue = decValue.ToString("X");

Для преобразования от шестнадцатеричного числа в десятичное число делают также...

int decValue = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);

или

int decValue = Convert.ToInt32(hexValue, 16);
265
ответ дан Legends 10 December 2018 в 09:52
поделиться
  • 1
    Да, я хочу избежать запросов mysql дважды. И в @Jon ответе Benedicto, he' s выполнение двух запросов.: ( – Prashant 29 April 2009 в 13:57

Похоже, что можно сказать

Convert.ToInt64(value, 16)

для получения десятичного числа от hexdecimal.

наоборот:

otherVar.ToString("X");
26
ответ дан Peter Mortensen 10 December 2018 в 09:52
поделиться

От Geekpedia:

// Store integer 182
int decValue = 182;

// Convert integer 182 as a hex in a string variable
string hexValue = decValue.ToString("X");

// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
5
ответ дан Tudor 10 December 2018 в 09:52
поделиться
String stringrep = myintvar.ToString("X");

int num = int.Parse("FF", System.Globalization.NumberStyles.HexNumber);
2
ответ дан Sklivvz 10 December 2018 в 09:52
поделиться
  • 1
    Моя единственная точка (который я сделал скорее verbosely) - то, что необходимо запустить где-нибудь; it' s проблема курицы-и-яйца. Вы can' t [только 110] украшают методы @Inject и ожидают, что что-либо произойдет. Что-то, где-нибудь, должно назвать injector.getInstance () или injector.injectMembers () для начинания всего этого. – David Noha 22 March 2012 в 21:43

Шестнадцатеричное число-> десятичное число:

Convert.ToInt64(hexValue, 16);

Десятичное число-> Шестнадцатеричное число

string.format("{0:x}", decValue);
51
ответ дан Jonathan Rupp 10 December 2018 в 09:52
поделиться
    static string chex(byte e)                  // Convert a byte to a string representing that byte in hexadecimal
    {
        string r = "";
        string chars = "0123456789ABCDEF";
        r += chars[e >> 4];
        return r += chars[e &= 0x0F];
    }           // Easy enough...

    static byte CRAZY_BYTE(string t, int i)     // Take a byte, if zero return zero, else throw exception (i=0 means false, i>0 means true)
    {
        if (i == 0) return 0;
        throw new Exception(t);
    }

    static byte hbyte(string e)                 // Take 2 characters: these are hex chars, convert it to a byte
    {                                           // WARNING: This code will make small children cry. Rated R.
        e = e.ToUpper(); // 
        string msg = "INVALID CHARS";           // The message that will be thrown if the hex str is invalid

        byte[] t = new byte[]                   // Gets the 2 characters and puts them in seperate entries in a byte array.
        {                                       // This will throw an exception if (e.Length != 2).
            (byte)e[CRAZY_BYTE("INVALID LENGTH", e.Length ^ 0x02)], 
            (byte)e[0x01] 
        };

        for (byte i = 0x00; i < 0x02; i++)      // Convert those [ascii] characters to [hexadecimal] characters. Error out if either character is invalid.
        {
            t[i] -= (byte)((t[i] >= 0x30) ? 0x30 : CRAZY_BYTE(msg, 0x01));                                  // Check for 0-9
            t[i] -= (byte)((!(t[i] < 0x0A)) ? (t[i] >= 0x11 ? 0x07 : CRAZY_BYTE(msg, 0x01)) : 0x00);        // Check for A-F
        }           

        return t[0x01] |= t[0x00] <<= 0x04;     // The moment of truth.
    }
1
ответ дан 23 November 2019 в 23:02
поделиться
Другие вопросы по тегам:

Похожие вопросы: