Results 1 to 1 of 1

Thread: [RESOLVED] byte(1) to int16

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    43

    Resolved [RESOLVED] byte(1) to int16

    Hi,

    I'm reading in data over the serial port into a byte array, however the data I'm receiving is 16bit integers.

    I need some help converting the byte array to to int16.


    I remember doing something similar a couple years ago in C. I was reading in bytes over the serial port, and converting them to 32bit floats.

    In C, I was able to declare a union, which was essentially a struct, except the contents of the union all shared the same memory space. So by declaring a 4-element byte array, I was able to write specific bytes into a float.

    Is there anything similar to this in vb.net? or another way perhaps?

    thanks,
    ioll


    edit:


    nvm, i think I got it.

    trying this...
    Code:
     Dim test() As Byte = {183, 55}
    
            Dim test1 As Int16 =BitConverter.ToInt16(test, 0))
    Last edited by ionlylooklazy; Aug 28th, 2007 at 02:46 PM.

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