Results 1 to 4 of 4

Thread: Bit manipulation in VB.NET

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Location
    Florida/Maryland
    Posts
    21

    Wink Bit manipulation in VB.NET

    Is there anyone that can tell me how to parce the Bits in a "Single" and store the most significant and least significant 16 bits in two separate Int16.

    Thanks in advance

    Terje

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. Dim f As Single = 3.2
    2.         Dim c() As Byte = BitConverter.GetBytes(f)
    3.         Dim s1 As Int16 = BitConverter.ToInt16(c, 0)
    4.         Dim s2 As Int16 = BitConverter.ToInt16(c, 2)
    5.  
    6. 'fluff to show it worked
    7.  
    8.         Dim s3 As Single = BitConverter.ToSingle(c, 0)
    9.         MessageBox.Show("Int16 #1: " & s1.ToString)
    10.         MessageBox.Show("Int16 #2: " & s2.ToString)
    11.         MessageBox.Show("Confirm: " & s3.ToString)
    Last edited by nemaroller; Jul 19th, 2004 at 08:38 PM.

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Can't answer your question right now but...

    You know, for a long time, I have been fascinated by bits and bytes. If I was old enough to be an assembly programmer, I'd probably know this. About as far as I've gotten is to manipulate bits by using OR or MOD or something like that on integers.

    I didn't even know how singles were stored until I read your post and googled it. MS uses the IEEE definition, which is:

    Code:
    Bits Usage 
    31 Sign (0 = positive, 1 = negative)
    30 to 23 Exponent, biased by 127
    22 to 0 Fraction f of the number 1.f
    Given that, and that you want a 4 byte (32 bit) single broken up into Int16's - which is a 16 bit *signed* integer, umm - what are you doing here - communicating with someone's API?

    Sorry I can't help directly,
    Mike

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Chingole. I didn't even know that the BitCoverter class existed. Please ignore my post and listen to the guy who knows what's going on.

    Geez... sorry

    Mike

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