|
-
Jul 19th, 2004, 05:51 PM
#1
Thread Starter
Junior Member
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
-
Jul 19th, 2004, 08:32 PM
#2
I wonder how many charact
VB Code:
Dim f As Single = 3.2
Dim c() As Byte = BitConverter.GetBytes(f)
Dim s1 As Int16 = BitConverter.ToInt16(c, 0)
Dim s2 As Int16 = BitConverter.ToInt16(c, 2)
'fluff to show it worked
Dim s3 As Single = BitConverter.ToSingle(c, 0)
MessageBox.Show("Int16 #1: " & s1.ToString)
MessageBox.Show("Int16 #2: " & s2.ToString)
MessageBox.Show("Confirm: " & s3.ToString)
Last edited by nemaroller; Jul 19th, 2004 at 08:38 PM.
-
Jul 19th, 2004, 08:48 PM
#3
Frenzied Member
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
-
Jul 19th, 2004, 08:56 PM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|