c# - Perform signed arithmetic on numbers defined as bit ranges of unsigned bytes -


i have 2 bytes. need turn them 2 integers first 12 bits make 1 int , last 4 make other. figure can && 2nd byte 0x0f 4 bits, i'm not sure how make byte correct sign.

update: clarify have 2 bytes

byte1 = 0xab byte2 = 0xcd 

and need it

var value = 0xabc * 10 ^ 0xd; 

sorry confusion.

thanks of help.

ok, let's try again knowing we're shooting for. tried following out in vs2008 , seems work fine, is, both outone , outtwo = -1 @ end. you're looking for?

byte b1 = 0xff; byte b2 = 0xff; ushort total = (ushort)((b1 << 8) + b2); short outone = (short)((short)(total & 0xfff0) >> 4); sbyte outtwo = (sbyte)((sbyte)((total & 0xf) << 4) >> 4); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -