Advertisement
sniper_nuko

swap_bit

Oct 29th, 2020
2,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. // 16ビット上位/下位入れ替え
  2. int swap_bit(uint16_t x)
  3. {
  4.     uint16_t u_bit = 0x0;       // 上位ビット
  5.     uint16_t l_bit = 0x0;       // 下位ビット
  6.     uint16_t swap_b = 0x0;      // 上位,下位ビット入れ替え格納
  7.    
  8.     // 上位ビット取得 8ビット右シフト
  9.     u_bit = x >> 8;
  10.     // 下位ビット取得 論理積
  11.     l_bit = x & 0x00FF;
  12.     // 上位,下位入れ替え
  13.     swap_b = (db << 8) | ub;
  14.    
  15.     // ビット入れ替え反映
  16.     return(swap_b);
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement