Bit Shifting for Flags ( Constructive Criticism Please)

I came up with a class that handles flag manipulation using Bitwise operators. Does anyone think this is more efficient than using boolean variables for flags? Or is this just overkill.
The reason Im asking is Ive used this approach before on Muds that I have written/updated. Just wondering if it is outdated.
* Allows for 64 different on/off flags.
public class State
        public static final byte ST_00 = (byte)0 ;
        public static final byte ST_01 = (byte)1 ;
        ....fill here......
        public static final byte ST_63 = (byte)63 ;
     private int lowStates = 0;
     private int highStates = 0 ;
     public boolean is( byte bitIndex )
          if( bitIndex > 31 )     
               return ( (highStates & ( 1 << (bitIndex%32) )) == 1 ? true :  false ) ;
          else
               return ( (lowStates & ( 1 << bitIndex ) ) == 1 ? true : false ) ;
     public void remove( byte bitIndex )
          if( bitIndex > 31 )
               highStates &= ~(1 << (bitIndex%32) ) ;
          else
               lowStates &= ~(1 << bitIndex ) ;
     public void set( byte bitIndex )
          if( bitIndex > 31 )
               highStates |= (1 << (bitIndex%32) ) ;
          else
               lowStates |= (1 << bitIndex ) ;
     public void toggle( byte bitIndex )
          if( bitIndex > 31 )
               highStates ^= (1 << (bitIndex%32) ) ;
          else
               lowStates ^= (1 << bitIndex) ;
* Simple implementation
public class INeedFlags
       public static final byte FLAG_1 = ST_00 ;
       public static final byte FLAG_2 = ST_01 ;
       public State flags = new State() ;
       public static void main(String[] args)
            INeedFlags obj = new INeedFlags() ;
            obj.flags.set( FLAG_1 );
            obj.flags.toggle( FLAG_2 ) ;
            if( obj.flags.is( FLAG_1 ) )
               System.out.println("Yep its set");
}

i often use bit flags.
my variation is to have the flag constants as long bitmasks.
this allows for multiple flag set / test in one instruction :
if (flags.has(FLAG_1 | FLAG_3)) {..}
also no bitshifting required should make it as fast as comparing booleans.
( in c++, the compiler optimises it away to almost nothing).
the java code is a quick hack of your post (sorry about the indents)
Adrian
  * Allows for 64 different on/off flags.
public class State
    public static final long ST_00 = 0x00000001 ;
    public static final long ST_01 = 0x00000002 ;
    public static final long ST_02 = 0x00000004 ;
  ....fill here......
    public static final long ST_62 = 0x40000000 ;
    public static final long ST_63 = 0x80000000 ;
    public State(long bitFlags)
        state = bitFlags;
    private int state = 0;
    public long value()     
        return ( state );
    public boolean equals( long bitFlags )
        return ( state == bitFlags ) ;
    public boolean is( long bitFlag )
        return ( has(bitFlag) ) ;
    public boolean has( long bitFlags )
       return ( (state & bitFlags) != 0 ) ;
     public void clear( )
          state = 0 ;
     public void remove( long bitFlags )
          state &= ~bitFlags ;
     public void set( long bitFlags )
          state |= bitFlags ;
     public void toggle( long bitFlags )
          state ^= bitFlags ;
  * Simple implementation
public class INeedFlags
        public static final long FLAG_1 = ST_00 ;
        public static final long FLAG_2 = ST_01 ;
        public static final long FLAG_3 = ST_02 ;
        public State flags = new State() ;
        public static void main(String[] args)
         * This still works
             INeedFlags obj = new INeedFlags() ;
             obj.flags.set( FLAG_1 );
             obj.flags.toggle( FLAG_2 ) ;
             if( obj.flags.is( FLAG_1 ) )
                System.out.println("Yep its set");
           * but you can also say
             obj.flags.clear( );
             obj.flags.set(FLAG_1 | FLAG_2);
             if( obj.flags.has( FLAG_2 | FLAG_3 ) )
                System.out.println("one of them is set");

Similar Messages

  • Problems with bit shift left in Formula Node

    Hi,
    Sorry but my English is not good.
    I'm trying to execute a bit shift left in the Formula Node, but the shift left is not working as I expected.
    uInt32 parametro[5];
    float32 valorAmostra;
    int16 indiceAmostra;
    uInt8 indiceResposta;
    int16 controle;
    int32 valor;
    int8 i;
    for(i=0; i<5; i++)
    parametro[i]=param[i];
    valor = parametro[5]<<16 | parametro[4]<<8 | parametro[3];
    controle = parametro[1]<<8 | parametro[0];
    indiceAmostra = (controle & 0x3FF);
    indiceResposta = (controle >> 10);
    valorAmostra = valor & 0x7FFFFF;
    valorAmostra = valorAmostra*(2.4/8388607);
    if((valor & 0x800000) == 0x800000)
    valorAmostra = valorAmostra*(-1);
    the input param array is of the type uInt8, as I saw in other topics that does not shift with uInt8,
    I copy the values of param array to parametro which is of type  uInt32, but still did not work.
    Testing the input param with the following values:
    param[] = {10,14,10,0,16}
    the valorAmostra returned is 0,00117188 when he should be 0,300003.
    Can someone help me please?
    Solved!
    Go to Solution.

    Portuguese:
    Olá,
    Existe um bug no LabVIEW para esta operação. Este bug deverá ser corrigido em versões futuras. Uma solução para esta situação é utilizar um int32 ao invés de um ulnt32.
    Qualquer dúvida por favor entre em contato.
    Obrigado.
    English:
    I investigated the problem you are having, and it turns out that it is a bug that has already been reported and documented. The work around for it is to use int32 rather than uInt32.
    Thanks.
    Luciano Borges
    R&D Engineer
    Pirelli Brazil

  • After  a system restore, I get an error message telling me that "This version of iTunes has not been correctly localized for this language.  Please run the English version." the E

    I did a system restore, trying to get rid of the new update (which I HATE), and now when I try to open iTunes, I get an error message telling me that "This version of iTunes has not been correctly localized for this language.  Please run the English version."  You can't change the language option unless you can open iTunes - and IT WON'T OPEN!!!  What a piece of crap!  If there existed an iTunes substitute, I would purchase it in a hot minute! 

    Strip it out and start again.
    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down the page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    If you really want to roll back to 11.4 uninstall all iTunes/Apple components as described in the second box, restore the pre-upgrade version of the library as described in Empty/corrupt iTunes library after upgrade/crash, then download and install from one of these direct links:
    iTunes 11.4.0.18 for Windows (32-bit) - iTunesSetup.exe (2014-09-09)
    iTunes 11.4.0.18 for Windows (64-bit) - iTunes64Setup.exe (2014-09-09)
    tt2

  • Windows 7 64 bit Drivers for HP Designjet H45500

    Hello everyone,
    Please help me to find a Windows 7 64 bit driver for HP Designjet H45500
    Thanks
    DIN

    Download and install the latest software for your printer from the "Support & Drivers" link at the top of this page.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Photoshop v7.0 I get the error "missing or invalid personalization information"  This used to run, I'm now on Windows 7 64 bit.  Anyone have any ideas please?  Thanks.

    I get the error "missing or invalid personalization information"  This used to run, I'm now on Windows 7 64 bit.  Anyone have any ideas please?  Thanks.

    Hi,
    If my memory serves me right (it’s some while since I changed and I have not used Photoshop for some years…) I was running it on XP.  I upgraded to Win 7 on  a new machine but ported across files, programmes etc.  I cannot recall if Photoshop ever ran on Win 7.
    I have tried to reinstall but the CD is warped and despite applying pressure to it neither of my drives likes it.  I have Photoshop 7 on my third hard drive, a portable drive, which came from the XP machine.
    Sorry, long-winded but I hope it helps.

  • Windows 7 64 bit driver for the Zen Vision M?

    - Where EXACTLY can I find the Windows 7 64-bit driver for the Zen Vision M? My new computer came with it installed in Windows Media Player 2, but the driver became corrupt. I can't seem to find that driver on the Creative or Microsoft download websites. Please Help!

    The driver is nati've to Windows. Creative does not write the MTP driver. I would suggest re-install WMP2 or contact Microsoft for advice if it is corrupt. As for software to use the player on a 64 Win 7system? there is nothing for the Vision M. You may want to read this page? http://support.creative.com/KB/showarticle.aspx?sid=605&h=3

  • Is Windows 7 64 bit support for Oracle Forms and Reports 6i version

    Hi All,
    Greentings!
    Its urgent requirement from customer to Install Oracle Forms and Reports 6i Client software in Windows 7 64 bit OS.
    Can any one please help me to download and Install the same. It would be great if you send me the download link and steps to Install.
    Many thanks in advance!
    Kind Regards,
    Mohan

    That is a very very old product. It does not look like it is certified on that OS.
    Forms 6i Documentation
    http://www.oracle.com/technetwork/documentation/6i-forms-084462.html
    From
    http://download.oracle.com/otn_hosted_doc/forms/forms/A73154_01.pdf
    1.2.1.2 Operating System
    This version of Forms Developer requires Microsoft Windows. Specifically, one of the following versions:
    Windows 95 (any version)
    Windows 98 (any version)
    Windows NT (Service Pack 5 or later)
    For certification you should check with Middleware Certification (MOSC)

  • After updating my Macbook Pro retina display to os x yosemite 10.10.2, the mause and track pad locks, and do not respond especially when using the Mac for a long period, please help, how can I solve this, I do not like feel like in windows, so I paid

    after updating my Macbook Pro retina display to os x yosemite 10.10.2, the mause and track pad locks, and do not respond especially when using the Mac for a long period, please help, how can I solve this, I do not like feel like in windows, so I paid good money for this mack, I feel calm

    Hi Buterem,
    I'm sorry to hear you are having issues with your MacBook Pro since your recent Yosemite update. I also apologize, I'm a bit unclear on the exact nature of the issue you are describing. If you are having intermittent but persistent responsiveness issues with your mouse or trackpad, you may want to try using Activity Monitor to see if these incidents correspond to occupied system resources, especially system memory or CPU. You may find the following article helpful:
    How to use Activity Monitor - Apple Support
    If the entire system hangs or locks up (for example, if the system clock freezes and stops counting up), you may also be experiencing some variety of Kernel Panic. If that is the case, you may also find this article useful:
    OS X: When your computer spontaneously restarts or displays "Your computer restarted because of a problem." - Apple Support
    Regards,
    - Brenden

  • Been stuck for over  a year, please help me do this

    so i have this laptop with 8gb ram and core i7 as well as 2 hdd (no raid).
    Now i heard about premiere (cs4) and my laptop is ready to take most of the advantage but the hard drive is the bootleneck.
    Basically, all i want is to do few cuts in a video that was filmed by sony hdr-sr11 camcoder in hd 1080 60i settings. Now i heard i need 3 hard drives etc, but at the moment, i only have 2.
    So is there anyway i can do simple cuts in premiere without losing any quality and slowdown in fps or is there any other software that can be better? I really don't want to lose any quality or fps with the g73jh-a2 asus laptop i have?
    i also have ati 5870 video card

    The lowest was 19mb, but was floating arond 30mb. Still that aint good..
    I can't afford the partition magic and i heard its not good to partition after installing windows. I am thinking of fresh install, but if there is a workaround, it would save me tons of time as not installing apps etc.
    For the setup
    1)Can i have the programs in secondary drive? What about just a game or 2?
    2)By projects, do you mean the videos that im going to edit?
    3)what is scratch?
    4) By media, do you mean videos im going to edit?
    Lastly, what about a bit of data? Like <50gb.. Pictures documents etc
    Like, truly anonymous
    Date: Fri, 30 Apr 2010 17:16:10 -0600
    From: [email protected]
    To: [email protected]
    Subject: been stuck for over  a year, please help me do this
    i did hdtune and was the os drive was 100mb-19mb in the end and the
    secondary one was 105-45~mbps
    Those figures are disturbing. For any reasonably modern 7200 RPM disk these figures should be around 120 - 60 MB/s. If it goes down to below 20, something is seriously wrong. Now that may be caused by your partitioning or something else, hard to discern from here, but these results are worrisome.
    Maybe Partition Magic can help you get rid of all these partitions, otherwise a complete reformat and fresh install of OS & programs is all that is left.
    Setup should be something like this:
    C: OS & programs & projects
    D: Pagefile, scratch and media
    It depends a bit on the nature of your projects, your workflow, but in general you set up your disks in such a way that disk accesses are spread over the available disks as much as possible.
    >

  • Bit Shifting Help

    Hi,
    I'm not too familiar with bit shifting. If anyone can help with this problem, it would be great!
    We have words that are 32 bits. So, basically, the lower 8 bits should have value �1� and the upper 24 bits should have value �X�. For our example, lets say 5. How do you manipulate integers to get this format? So, I assume it will look like below.
    31 87 0
    00000000010100000001

    int i = 0x12345678;
    byte highOrder = (byte)(i >> 24);
    byte second = (byte)(i >> 16);
    byte third = (byte)(i >> 8);
    byte lowOrder = (byte)i;

  • Existing 64 bits driver for PCI Synchro board Computer Conversions Corporation

    existing 64 bits driver for PCI Synchro board from Computer Conversions Corporation ?
    Thank's for your answer

    You will have to contact Computer Conversions Corporation for that information:
    http://www.computerconversions.com/ccc/index.html
    Microsoft does not produce the drivers for third party hardware.  That is the sole responsibility of the manufacturer.
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”

  • Steps to create 64 bit Addon for SAP 9.0 compatible

    Hi All,
    I am trying to create the 64 bit addon for sap 9 compatible.
    But getting errors.
    Please give me steps.

    Hi Pravin,
    What is the error ?
    What steps have you tried ?
    Regards
    Edy

  • Implementation of SAP Business One for a construction Company

    Hello Everyone,
    This is Anuradha, we are going to implement B1 for a construction company for the first time.The Client requirement is as follows: " There are four branches under a Head office, the Board of Directors who are at the HO should be able to access the consolidated reports of all the Branches(which hold the different construction projects)...How to configure  this so that all the consolidated reports to be viewed by the HO at the end of the day ...
    Plz do help me out with a solution asap ......
    Regards,
    AnuradhaSantosh

    Anuradha,
    You should look at the option of creating Segmented Accounts.  Segmentation facilitates defining branches and without any additional effort, the Directors of the copy would be able to run any Accounting / Financial Report which would show the consolidated results.
    Unless, you are planning to setup 4 different company database for each branch where the scenario is much different and will require consolidation.
    Please let me know if you need further direction
    Suda

  • How To Download 32 Bit PE10 for Vista 64 Bit PC?

    I purchased a bundled Adobe Photoshop Elements 10 & Premiere Elements 10.  When attempting to install Premiere Elements 10 I received an error stating..
    This installer does not support 64 Bit Windows XP or Vista.  If you are installing from discs pelase remove ths disk and insert disk #1.  If you are not installing from disk please download the 32-bit version of Premiere Elements 10. 
    I have only one disk in the bundle for Windows (the other is for the MAC OS)  Where/How can I download Premiere Elements 10 or a 64 bit installer for Vista for the disk I have.  I'm guessing my serial numbers are only valid for PE10.
    Thank you.

    Thank you both B. Hunt and J. Smith for the time and thought spent on my issue.   I feel the root cause of my issue is described in my post #4 through the
    Adobe support link: http://helpx.adobe.com/premiere-elements/kb/cannot-install-premiere-el ements-10.html
    which describes the the 64bit installer not working on 64 bit XP or bit 64bit Vista PCs.  The support article further describes how to download a 32 bit version of Premier Elements 10 and install on my 64 bit Vista machine.
    While the OEM version of the software seems to be a contributor to the confusion and lacking multiple discs, the support article did not suggest that it was a packaging/bundling issue, but more so an incompatibility of operating systems and software installers.   I agree that the bait and switch by the seller (picture one thing and ship another) didn't help and I will be taking it up with them (and Amazon).  That said, not seeking to pay list price for cars, appliances, or software isn't unethical, switching or not disclosing what one is selling however is unethical.
    I followed the instructions in the Adobe support post and the 32 installer worked on my 64 bit Vista machine.  I stopped just short of entering the license code as I plan to upgrade to Windows 7 64bit in order to use the 64bit version of the PE10 - which I feel would perform faster.  I'd expect that the installer would work as it did for Photoshop Elements 10 on the same OEM bundle.  My fallback position is to run the 32 bit version on the Win7 64bit machine after I upgrade.
    Finally, I'm a hobbyist, just looking to create a DVD capturing a recent family reunion.  That was my objective and I'm closer to achieving it as a result of Adobe Support and your contributions.  Thank you.

  • IMAQ Array to Image Bit Shift?

    Hi,
    I've been working with some 12 bit images from a camera and saving the results as 16 bit TIFFs using some of the Vision VIs.  I can save and read back in the TIFFs and all of the data stays intact, but if I try to open the saved TIFFs in another reader (e.g. MATLAB), the returned data is incorrect.  Opening the raw TIFF files and looking at the image data (little endian) in bytes, numbers like 234 001 [490] end up becoming 234 129 [33258].  From the attached VI, it becomes clear there's a problem when you simply put in zeros to the array and try to open up the resultant TIFF in MATLAB (0 goes to 2^15) and yet LabView reads in the TIFF just fine.  While I can work around this problem, I only know I that need to work around it if I know a priori that the TIFF is from LabView.  Is there some resolution to this problem?  I'm thinking some kind of bit shifting to the data in LabView before converting the array to an image.  Thanks.
    Attachments:
    array_to_tiff.vi ‏49 KB

    Hello,
    Maybe you are looking for the functions "swap byte" and "swap words"
    Hope this helps
    Message Edité par TiTou le 06-29-2007 02:00 PM
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    swap.png ‏409 KB

Maybe you are looking for