<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
    主站蜘蛛池模板: 最近中文字幕完整免费视频ww| 无码人妻AV免费一区二区三区| 日本视频一区在线观看免费| 国产亚洲A∨片在线观看| 黄 色一级 成 人网站免费| 久久精品国产亚洲Aⅴ蜜臀色欲| 亚洲一区精品中文字幕| 99久久久国产精品免费牛牛| 亚洲伊人tv综合网色| 日本免费一区二区在线观看| 国产成人精品日本亚洲18图| 毛片免费在线播放| 色偷偷噜噜噜亚洲男人| 亚洲日本中文字幕一区二区三区| 国产精品美女免费视频观看| 亚洲AV午夜成人影院老师机影院| 免费国产黄网站在线观看视频| 亚洲精品视频免费看| 一级做a爰片久久毛片免费陪| 国产啪亚洲国产精品无码 | 一级做a爰片久久毛片免费陪| 国产国拍精品亚洲AV片| 久久国产乱子伦精品免费不卡| 亚洲一级毛片中文字幕| 韩国18福利视频免费观看| 老司机午夜在线视频免费| 亚洲精品国产精品乱码视色| 114一级毛片免费| 天天综合亚洲色在线精品| 亚洲精品国产成人片| 老司机在线免费视频| 五月天婷婷精品免费视频| 日韩亚洲人成在线综合日本| 桃子视频在线观看高清免费完整| 美景之屋4在线未删减免费 | 国产成人精品亚洲一区| 亚洲精品成人片在线观看精品字幕| 亚洲国产精品免费在线观看| 国产精品亚洲а∨天堂2021| 亚洲高清在线视频| 最新69国产成人精品免费视频动漫|