<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    七段

    無論怎樣,請讓我先感謝一下國家。

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      35 Posts :: 2 Stories :: 7 Comments :: 0 Trackbacks
    java bitwise operator:
    ~ The unary bitwise complement operator "~" inverts a bit pattern.
    <<The signed left shift
    >>The signed right shift
    >>>the unsigned right shift

    & The bitwise & operator performs a bitwise AND operation.

    ^ The bitwise ^ operator performs a bitwise exclusive OR operation.

    | The bitwise | operator performs a bitwise inclusive OR operation.



    Usage:
    1,
    • ^ can swap two variables without using an intermediate, temporary variable which is useful if you are short on available RAM or want that sliver of extra speed.

      Usually, when not using ^, you will do:

      temp = a;

      a = b;

      b = temp;

      Using ^, no "temp" is needed:

      a ^= b;

      b ^= a;

      a ^= b;

      This will swap "a" and "b" integers. Both must be integers.

    2,
    an example of using an integer to maintain state flags (common usage):
    // These are my masks

    private static final int MASK_DID_HOMEWORK  = 0x0001;

    private static final int MASK_ATE_DINNER    = 0x0002;

    private static final int MASK_SLEPT_WELL    = 0x0004;



    // This is my current state

    private int m_nCurState;

    To set my state, I use the bitwise OR operator:

    // Set state for'ate dinner' and 'slept well' to 'on'

    m_nCurState
    = m_nCurState | (MASK_ATE_DINNER | MASK_SLEPT_WELL);

    Notice how I 'or' my current state in with the states that I want to turn 'on'. Who knows what my current state is and I don't want to blow it away.

    To unset my state, I use the bitwise AND operator with the complement operator:

    // Turn off the 'ate dinner' flag

    m_nCurState
    = (m_nCurState & ~MASK_ATE_DINNER);

    To check my current state, I use the AND operator:

    // Check if I did my homework

    if (0 != (m_nCurState & MASK_DID_HOMEWORK)) {

       
    // yep

    } else {

       
    // nope...

    }

    Why do I think this is interesting? Say I'm designing an interface that sets my state. I could write a method that accepts three booleans:

    void setState( boolean bDidHomework, boolean bAteDinner, boolean bSleptWell);

    Or, I could use a single number to represent all three states and pass a single value:

    void setState( int nStateBits);

    If you choose the second pattern you'll be very happy when decide to add another state - you won't have to break existing impls of your interface.


    posted on 2010-04-13 14:39 sevenduan 閱讀(413) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲成AV人片在线观看ww| 亚洲综合av一区二区三区| h视频在线观看免费完整版| 亚洲最大无码中文字幕| 亚洲国产精品日韩| 先锋影音资源片午夜在线观看视频免费播放| 亚洲欧洲日韩在线电影| 国产乱色精品成人免费视频 | 久久久久久a亚洲欧洲aⅴ| 131美女爱做免费毛片| 美女18毛片免费视频| 337p欧洲亚洲大胆艺术| 免费一级做a爰片久久毛片潮喷| 嫩草在线视频www免费观看| 亚洲精品乱码久久久久久V | 久久夜色精品国产噜噜噜亚洲AV| 毛片免费全部播放一级| 成全在线观看免费观看大全| 亚洲色大成WWW亚洲女子| 久久亚洲国产精品一区二区| 韩国日本好看电影免费看| 久久免费观看国产精品| 黄页网址大全免费观看12网站| 亚洲熟妇av一区| 中文字幕中韩乱码亚洲大片| 免费观看大片毛片| 日韩av无码久久精品免费| 人妻无码中文字幕免费视频蜜桃| 亚洲一区在线视频观看| 亚洲av无码成人黄网站在线观看 | 成年女人看片免费视频播放器| 美女视频黄的免费视频网页| 亚洲风情亚Aⅴ在线发布| 亚洲日本在线观看网址| 亚洲成AV人片在线观看| 亚洲人成色77777在线观看大| 成人黄动漫画免费网站视频 | 亚洲av永久中文无码精品综合| 99亚洲精品高清一二区| 亚洲无线码在线一区观看| 国产免费观看青青草原网站|