[英]How to check if a hex number is equal to a specific binary number?
嗨,我正在嘗試做一些應該很簡單的事情,但我無法弄清楚。 我有一個指向無符號字符數組的指針,我得到了第一個元素,它是一個十六進制數字。 我想將其轉換為二進制,以便檢查是否等於數字,例如0x01101000。
unsigned char arr[] = {0x25}; //just for example. I am actually using *arr.
unsigned char byte = arr[0];
if(( byte & 0x01101000) == //not sure if this is the right way to proceed
希望能有所幫助! 謝謝!!
看到這個答案。
如果您使用的是GCC,則可以為此使用GCC擴展名:int x = 0b00010000;
因此,在您的情況下,它將是:
if( byte == 0b01101000 )
...
不過,請務必在文字中只放入8位。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.