0

I have a ushort[3] data read from device. Now I want to convert it to the following format:

Picture Here

The first word ushort[0] --> 16 bits

The second word ushort[1] --> 8 bits & 2 * 4-bits

The Third word ushort[2] --> 4 * 4bits


For example:

The ushort[3] is 3 256 16

After converting:

The first word 0000 0000 0000 0011

The second word ushort[1] --> 0 1 0000 0000

The Third word ushort[2] --> 0 0 1 0


At last store it as byte[30] in c#

I hope I have clearly explain this problem, and welcome any suggestions. Thanks!

BarryLib
  • 299
  • 1
  • 5
  • 20
  • 1
    You example, does not fit your definition. ushort[1] is only 10 Bits (not 8 & 2 * 4 = 16) and ushort[2] is only 4 Bits (instead of 4 * 4 = 16) – Romano Zumbé Jul 17 '17 at 07:17
  • If you are trying to convert `ushort`s to binary form, you can find solution here: https://stackoverflow.com/questions/2954962/decimal-to-binary-conversion-in-c – vasek Jul 17 '17 at 07:19
  • @RomanoZumbé sorry for my expression. The yellow zone in the picture are 4-bits data which is not standard data type of C#, you can consider it as a byte whose high 4 bits default values are 0. – BarryLib Jul 17 '17 at 07:27

0 Answers0