Bitoperations with floating point numbers

P

Parity

Hello,

form my point of view, I'm haveing a really tiny problem, but I am not
able to solve it by myself.

My final goal is to be able to split 32bit floating point variables (as
Sinlgle) binary into 4 seperate bytes (which is necessary to work with a
given transmission protocol). Therefor I am trying to read and write
single bits in a floating point variable (e.g. Single).
I already succeeded with 32bit variables of the type Long. So my
problem would already be solved, if you can help me to write the 32
bits of the 32bit Single variable bitwise into the 32 bits of a 32bit
Long variable.


Code:
--------------------

dim s as Single
'dim s as Long
Dim bit(0 To 30) As Boolean

s = 12.34
's = 12

For j = 0 To 30
bit(j) = CBool(s And 2 ^ j)
Next j

--------------------


This code works fine for the commented line, when the variable s is of
type Long. When s is of type Single, VB automaticly casts the 12.34 to
an Integervalue of 12.

So how can I split (and recombine) the 32bit Singlevalue into Bytes
(8bit)?

Thanks in advance for your effort, Parity
 
P

Parity

I hope you are able to understand what my intensions are. Any suggstions
how I can continue solving my problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top