[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: float->bits
From: |
Marcus G. Daniels |
Subject: |
Re: float->bits |
Date: |
06 Dec 2000 09:21:42 -0800 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "JI" == Jonathan Impett <address@hidden> writes:
JI> In attempting to breed small networks within swarms, I
JI> need to read the single-precision floating point weights of the
JI> nets as vectors of bits for the GA, and vice-versa. Essentially,
JI> I need a float and an array of 32 chars which can exchange binary
JI> sequences.
Well, you can cast the address of the float to an unsigned char pointer.
It's not portable, of course...
E.g.
int
main ()
{
float val = 2.5;
float newval;
unsigned char *buf = (unsigned char *) &val;
unsigned char *newbuf = (unsigned char *)&newval;
newbuf[0] = buf[0];
newbuf[1] = buf[1];
newbuf[2] = buf[2];
newbuf[3] = buf[3];
printf ("%f\n", newval);
}
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
- float->bits, Jonathan Impett, 2000/12/06
- Re: float->bits,
Marcus G. Daniels <=