c# - Take the first half of a byte -


i'm looking more performant/elegant way taking first 4 bits of bytes. bytes in big endian

var gpsfixstatus = (int)raw[28]; int[] remainder = new int[8]; (int = 0; < 7; i++) {     remainder[i] = gpsfixstatus % 2;     gpsfixstatus = gpsfixstatus / 2; } var gpsfix = byte.parse((remainder[7].tostring() + remainder[6].tostring() + remainder[5].tostring() + remainder[4].tostring())); 

the first half of byte b is

b >> 4 

assuming want shifted lower 4 bits. if want still in place, removing bottom half, it's just

b & 240  // or "b & 0xf0" 

but looks code though former want.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -