Results 1 to 2 of 2

Thread: Add 2 BIts to beginning of a Byte

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    142

    Exclamation Add 2 BIts to beginning of a Byte

    I need to add two bits from one byte to the beginning of another 8 bit number. Example

    Byte 1 Byte 2
    00110011 11000100
    11------>11000100 to get 1111000100

    Plus this is happening at 300/second so the faster the better.

    I've read about the bitarray() class but they don't have a way to get more than one value from the bit array at a time.

    I also tried bitmasking the first 6 bits in byte one to get the last two bytes (which works) and then add them to byte2 but if I use the ampersan ("&") it just adds the value of the two bits to the value of the next 8 bits, Example:

    11 (Value of 3) to 00000111(value of 7) = 37
    not what I need
    If I use the "+" operator it just add the two numbers 3+7 = 10

    BUT I need the value for 1111000100 .

    Sorry if this is confusing at all.....

    Thanks,
    Bebandit

  2. #2
    Member
    Join Date
    May 2003
    Posts
    58
    There is a class called BitConverter. If I am not mistaken what you want is to get the decimal of 2 bytes ( which is Short data type). You can use this.....

    BitConverter.ToInt16(bytes, 0)

    where bytes consists of 2 bytes (or more) and byte1 and byte2 = 00110011 11000100.

    The resulting could be different on different OS. you need to make sure that the byte is stored in certain order (LittleEndian/BigEndian), and do byte swapping when necessary.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width