看板 Programming 關於我們 聯絡資訊
寫一函數,將一8bit的資料左右邊交換 void swap_byte(unsigned char p) 例如 unsign char p; p=0x38; q=swap_byte(p); q=0x83; 想到方法是 unsigned char a=0x01; 然後0x01<<=1;一個一個比較 最後前面四位元乘以16後面四個位元除以16 但unsign char用乘法運算好像也不是很正確 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.85.172.223
MOONRAKER:有 & | ~ ^ 這些bit operator好用 118.163.12.175 02/22 16:50
MOONRAKER:ㄟ對喔 你不用這些operator怎麼"比較"? 118.163.12.175 02/22 16:51
Leadgen:用and當作遮罩,把4個位元遮起來再來位移 114.24.62.198 02/23 20:59
xcode:p = (p << 4) | (p >> 4); 59.126.15.80 03/12 08:03