| | |
bitwise operations and masking
![]() |
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Solved Threads: 0
Hi
I have an array of float and i need to mask the values.
I want to be able to get arr[x] and arr[x+1] and then mask them and recombine them results in a radom order (im doing an evolutionary algorithm!)
But i cant get the masking to work, it always seems to return 1 as a reult.
This is the code that dosnt work:
mask[] is an arra of floats that stores the values I want to mask (as they need to be repeated through in order)
float mask[8] = { 0x0003, 0x0F0C, 0x0030, 0x00C0, 0x0300, 0x0C00, 0x3000, 0xC000 };
and chrom is where i want to store the incomplete values before ORing them together to make a complete float.
Any ideas on how to do the bitwise and with floats?? It just wont work!
Cheers.
I have an array of float and i need to mask the values.
I want to be able to get arr[x] and arr[x+1] and then mask them and recombine them results in a radom order (im doing an evolutionary algorithm!)
But i cant get the masking to work, it always seems to return 1 as a reult.
This is the code that dosnt work:
C Syntax (Toggle Plain Text)
for(x=size; x > 1; x--) { for(int y=0; y < 8; y++) { r = (int) (rand()%800); if(r < 400) { chrom[y] = (float) population[x] && mask[y]; }//end if if(r > 400) { chrom[y] = (float) population[x-1] && mask[y]; }//end if nGen[x] = (float) chrom[0] || chrom[1] || chrom[2] || chrom[3] || chrom[4] || chrom[5] || chrom[6] || chrom[7]; } //end y } // end x
mask[] is an arra of floats that stores the values I want to mask (as they need to be repeated through in order)
float mask[8] = { 0x0003, 0x0F0C, 0x0030, 0x00C0, 0x0300, 0x0C00, 0x3000, 0xC000 };
and chrom is where i want to store the incomplete values before ORing them together to make a complete float.
Any ideas on how to do the bitwise and with floats?? It just wont work!
Cheers.
>it always seems to return 1 as a reult.
I would imagine that's because both operands are non-zero. You're using the logical AND and logical OR rather than the bitwise AND and bitwise OR. The logical operators are && and ||, and the bitwise operators are & and |.
>It just wont work!
Correct. The bitwise operators only work with integral values.
I would imagine that's because both operands are non-zero. You're using the logical AND and logical OR rather than the bitwise AND and bitwise OR. The logical operators are && and ||, and the bitwise operators are & and |.
>It just wont work!
Correct. The bitwise operators only work with integral values.
I'm here to prove you wrong.
•
•
•
•
Originally Posted by mr_mooz
So how can I get round that? when i use just & or | i get an error.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
•
•
Originally Posted by mr_mooz
Thats ok, because i can check the validity of the floats that it would produce, they have to be within a certain range and its permissible to replace any malformed floats with a random but valid replacement.
So i dont mind if it dosnt always work, as long as it would work most of the time!
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- bitwise operations in C (C)
- Help with C bitwise code (C)
- Code Snippet: A Simple Look at Bitwise Operations (Python) (Python)
- Bitwise operators (C)
Other Threads in the C Forum
- Previous Thread: Inputting from files
- Next Thread: how do you set a variable to be a filename?
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






