Re: Simply C/C++ problem!

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Wed, 11 Aug 2010 09:18:04 -0500


Hi,

This seems to be the correct behavior because '1' is an int by default thus the result
of (int) << (int) is 32 bits. You may want to try:

    ULong64_t ULD;
    ULong64_t one = 1ULL;
    for (Int_t i=0; i<10; i++){

        printf("\n(%3i)", i+1);
         ULD=0;
         ULD|=one<<mem[i][0];
         ULD|=one<<mem[i][1];
         ULD|=one<<mem[i][2];
         ULD|=one<<mem[i][3];
         ULD|=one<<mem[i][4];
         ULD|=one<<mem[i][5];
         ULD>>=1;
         printf("  %llu ", ULD);
      }//for ith

Cheers,
Philippe.

On 8/11/10 6:18 AM, 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 - 16:55:36 CEST

This archive was generated by hypermail 2.2.0 : Thu Aug 12 2010 - 05:50:01 CEST