數字是一個字符串==「0x1388」,在dec中是5000。我不知道如何將這個十六進制字符串轉換爲int值== 0x1388;任何幫助?並提前致謝。如何使value = strtol(number.c_str(),NULL,number.size());工作?
value = strtol (number.c_str(),NULL, number.size());
數字是一個字符串==「0x1388」,在dec中是5000。我不知道如何將這個十六進制字符串轉換爲int值== 0x1388;任何幫助?並提前致謝。如何使value = strtol(number.c_str(),NULL,number.size());工作?
value = strtol (number.c_str(),NULL, number.size());
第三個參數是要轉換的數字的基數。在你的情況下,數字是基數16(十六進制),所以你應該通過16
作爲第三個參數。您也可以通過0
,這將使函數確定前綴0x
的基數。
修正第三個參數
value = strtol (number.c_str(),NULL, 16);
^^ Base of hexadecimal number
將這項工作八路和十二月呢? – user2904033
@ user2904033是的,爲什麼不呢? – P0W
http://stackoverflow.com/questions/1070497/c-convert-hex-string-to-signed-integer – IdeaHat