Re: Simply C/C++ problem!

From: Marc Escalier <escalier_at_lal.in2p3.fr>
Date: Wed, 11 Aug 2010 13:34:18 +0200


Hi,

since i'm a low level guy, maybe it is difficult to understand exactly what you need to do.

as far as i remember, to do some bits manipulations, you could use a kind of mask, doing something like this :

Isolate the bit that you wish to put to 1 or put to 0 with a mask and put it to 1 (with a OR to the bit to 1) or to 0 (with a AND to the bit to 0) :
destination= (destination & Mask) OPERATOR 0x....; with the last OPERATOR : | in the case of putting it to 1 with the last OPERATOR : & in the case of putting it to 0

where mask would be :
a) in the case of putting a bit to 1 :
0..010...0
b) in the case of putting a bit to 0 :
1..101...1

//where Mask is written either in binary or hexadecimal

by the way, "<<" is a shift of bit to left, ">>" is a shift or bit to right (i guess you know but just in case)



On Wed, 11 Aug 2010, Dr Ian Korir wrote:

> Dear ROOTers,
>
> I need to perform some simple bit "manipulations" without making use of
> the TBit ROOT object on a 64 bit variable ULD declared as (supposedly)
> unsign long long, then get a printout of the same variable using printf.
> My problem is it does not seem to work or seems to truncate the output
> to 32 bits. Here is the relevant portion of the code that does this:
>
> ULong64_t ULD;
> for (Int_t i=0; i<10; i++){
> printf("\n(%3i)", i+1);
> ULD=0;
> ULD|=1<<mem[i][0];
> ULD|=1<<mem[i][1];
> ULD|=1<<mem[i][2];
> ULD|=1<<mem[i][3];
> ULD|=1<<mem[i][4];
> ULD|=1<<mem[i][5];
> ULD>>=1;
> printf(" %llu ", ULD);
> }//for ith
>
> The mem[i][j] is a 2D array of Int_t etc and the process above is meant
> to set appropriate bits to 1 initialised with all zeros (supposedly),
> how can one fix this to perform as one might expect?
>
> Uses root version 5.26/00 under OS SL52 environment (HP Z600 64Bit Quad)
>
>
> Regards,
>
> Ian.
>
>
Received on Wed Aug 11 2010 - 13:34:29 CEST

This archive was generated by hypermail 2.2.0 : Wed Aug 11 2010 - 17:50:01 CEST