Manipulating numbers in Handel-C/C

Associate
Joined
25 Jul 2003
Posts
935
Location
London
Hi,

I have 4 numbers. I need to extract the first bit of each number and put them together to form a resulting binary number.

i.e. 12=00001100
100=01100100
4=00000100
5=00000101

So the first number I need would be 0001 and the second would be 0000 and so on. How would I go about implementing this in Handel-C or C.

Thanks

real
 
Ah. I think i've just remembered how to take the first bit of each of the numbers. I could logic AND the number with 0000001. But im still stuck on how to put the bits together.
 
Ah. I think i've just remembered how to take the first bit of each of the numbers. I could logic AND the number with 0000001. But im still stuck on how to put the bits together.

well you are half there already.

Assuming ive understood what you are after, OR all the bytes to together then AND them with 0x1


Or if you want to bit shift use << or >>

ie 0x1 << 3 = 0x8 (binary 0001 shift 3 places left = 1000)
 
Last edited:
Thank you for your reply.

So what I will do is this:

AND all the numbers with 0x1 to single out the first bit.

Then for the first number I do <<3, for the second <<2, the third <<1 and the fourth nothing. Then I add these together.
 
Thank you for your reply.

So what I will do is this:

AND all the numbers with 0x1 to single out the first bit.

Then for the first number I do <<3, for the second <<2, the third <<1 and the fourth nothing. Then I add these together.

sounds right to me.
 
Back
Top Bottom