éå¼ããããæ¼ç®ãªãã¡ã¬ã³ã¹
常èã¬ãã«ã®ãã¿ã§ããããã¾ã«ä½¿ãã¨å¿ãã¦ããããã®ã§ããã使ã?ãããæ¼ç®ãã次ã«ç¤ºããã¡ã¤ã«ã®æä½æ¨©éè¨å®ãä¾ã¨ãã¦ã¾ã¨ãã¦ã¿ã¾ãã
- ãã¡ã¤ã«ã«å¯¾ããæä½æ¨©éã3ãããã®æ°å¤ã§è¨é²ããã
- èªã¿è¾¼ã¿æ¨©.. 1ãããç®, æ¸ãè¾¼ã¿æ¨©..2ãããç® ã¨ããã
å権éã示ãå®æ°ã¯æ¬¡ã®éãã
# èªã¿è¾¼ã¿æ¨© READ = 1 << 0 # 001 # æ¸ãè¾¼ã¿æ¨© WRITE = 1 << 1 # 010 # ãã¹ã¦ã®æ¨©é ALL = READ | WRITE # 011 # 権éãªã NONE = 0 # 000
ç¹å®ã®ããããonã«ããã
ãorãã使ãã以ä¸ã¯æ¸ãè¾¼ã¿æ¨©ãä»ä¸ããä¾ã
# æ¸ãè¾¼ã¿æ¨©ãä»ä¸ puts NONE | WRITE # 010
ç¹å®ã®ããããoffã«ããã
ãå転ãã¦andããããèªã¿è¾¼ã¿æ¨©ãå¥å¥ªã
# èªã¿è¾¼ã¿æ¨©ãå¥å¥ª puts ALL & ~READ # 010
ã3ãããç®ã¯ãã¦ã¼ã¶ã¼ã«è¦ããªãé ããã©ã¡ã¼ã¿ãªã®ã§å¿ ãoffã«ããç¶æ ã§è¨é²ãåç §æãoffã«ãã¦è¿ããæã¨ãã«ã使ãã
ç¹å®ã®ãããã®on/offãå¤å®ãããã
ãandãã使ããèªã¿è¾¼ã¿æ¨©ããããã©ããããã§ãã¯ããã
# èªã¿è¾¼ã¿æ¨©ããããè©ä¾¡ puts ALL & READ != 0 # true puts NONE & READ != 0 # false
ãã¾ã:ä»æ¥ã®æç³»ããã°ã©ã
æ(éãæã ããã!)ã|ãã¨ãã&ãã使ãã®ç¥ããªãã¦ãã+,-ãã§ãã£ã¦ããªã¼(é ãç®)
# 権é privilege = 0 privilege += READ # èªã¿è¾¼ã¿æ¨©ãä»ä¸ privilege -= READ # èªã¿è¾¼ã¿æ¨©ãå¥å¥ª
ä¸å¿åããã ãã©ãã»ã»ã»ãããon/offå¤å®ã¯ã©ããã£ã¦ããã ããæãåºããã