[問題] most significant bit
各位大大好,
請問如果給您選擇,
您會選哪個函式來找出MSB呢?
int get_highest_bit_position(unsigned char x)
{
int n = 7;
if (x == 0) return -1;
if ((x >> 4) == 0) { n = n-4; x=x << 4;}
if ((x >> 6) == 0) { n = n-2; x=x << 2;}
if ((x >> 7) == 0) { n = n-1;}
return n;
}
int get_highest_bit_position(unsigned char x){
for(int i = 7; i >= 0 ; --i){
if(0b10000000 & x){return i;}
else{x = x << 1;}
}
return 0;
}
謝謝!
-----
Sent from JPTT on my iPhone
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.137.49.99 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1679815376.A.FA6.html
推
03/26 16:43,
1年前
, 1F
03/26 16:43, 1F
→
03/26 16:44,
1年前
, 2F
03/26 16:44, 2F
→
03/26 16:45,
1年前
, 3F
03/26 16:45, 3F
→
03/26 16:45,
1年前
, 4F
03/26 16:45, 4F
推
03/27 07:52,
1年前
, 5F
03/27 07:52, 5F
→
03/27 07:54,
1年前
, 6F
03/27 07:54, 6F
→
03/27 18:38,
1年前
, 7F
03/27 18:38, 7F
→
03/29 00:40,
1年前
, 8F
03/29 00:40, 8F
→
03/29 00:41,
1年前
, 9F
03/29 00:41, 9F
推
04/03 17:55,
1年前
, 10F
04/03 17:55, 10F
推
04/05 09:46,
1年前
, 11F
04/05 09:46, 11F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章