[英]How to convert hexadecimal value to integer in c++?
我在 unsigned char 中有十六進制值,但我找不到任何方法將此十六進制值更改為整數。 請對此提供幫助。
unsigned char c = '0x01';
int convertasint = (int)c;//not working
int convertasint1 = (atoi)c;//not working
請指導我如何實現這一目標。
unsigned char
變量已經是整數( char
)。 您無需執行任何特殊操作即可轉換它們。 此代碼有效
unsigned char c = 0x01; // assign integer to unsigned char
int convertasint = c; // now assign to int
cout << convertasint << '\n'; // this prints 1
另請注意,十六進制整數只是整數,就像十進制整數一樣。 您也不需要在它們之間進行轉換。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.