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
Printable View
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
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)
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:
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?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
Sorry I can't help directly,
Mike
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