1

I wrote this helper method to unpack a byte onto nibbles:

public static void Deconstruct(this byte value, out byte nibble1, out byte nibble2)
{
    nibble1 = (byte) ((value >> 00) & 0x0F);
    nibble2 = (byte) ((value >> 04) & 0x0F);
}

Then naturally, I thought doing the same for sbyte (signed byte):

public static void Deconstruct(this sbyte value, out byte nibble1, out byte nibble2)
{
    nibble1 = (byte) ((value >> 00) & 0x0F);
    nibble2 = (byte) ((value >> 04) & 0x0F);
}

But well, sbyte is a bit confusing to say the least.

Question:

When unpacking a sbyte (signed byte) as nibbles, should these nibbles also be signed or not?

aybe
  • 15,516
  • 9
  • 57
  • 105
  • 6
    Unsigned. Nybbles are 4 bits. If you were to consider them signed, you'd have to sign-extend them. Those extra bits wouldn't be of any value and they'd be lost when you repack them. For simplicity, consider them unsigned, even when the packed value is signed. – madreflection Feb 26 '20 at 07:16
  • 1
    That makes sense, thank you. Post an answer if you want and I'll accept it. – aybe Feb 26 '20 at 08:36

0 Answers0