TAILIEUCHUNG - C 2.0 practical guide for programmers PHẦN 5

Cho a, b là các giá trị bit tương ứng trong các toán hạng bên trái và bên phải, tương ứng, khai thác hợp lý (bitwise) được định nghĩa như trong Bảng . Đảo ngược giá trị bit (Bổ sung) 1 nếu cả hai bit là 1, nếu không 0 1 nếu một trong hai hoặc cả hai bit là 1, nếu không 0 1 nếu và chỉ nếu một trong các bit là 1, khác 0 | Logical Operators 89 t b where f not evaluated short-circuited 0 t b f f b where t not evaluated short-circuited 0 f t b f f where b not evaluated short-circuited 0 f f b t b where f not evaluated short-circuited 0 f t b Output True False False False True True True False True True False True Logical Operators Given that a and b are corresponding bit values in the left-hand and right-hand operands respectively the logical bitwise operators are defined as in Table . Name Notation Meaning Logical NOT a Logical AND a b Logical OR a b Logical XOR a b Invert the bit value Complement 1 if both bits are 1 otherwise 0 1 if either or both bits are 1 otherwise 0 1 if and only if one of the bits is 1 otherwise 0 Table Logical operators. a b a a b a b a b 1 1 0 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 0 1 0 0 0 Table Values for logical operators. 90 Chapter 5 Operators Assignments and Expressions Valid types for logical operators are integers and boolean. Example public class LogicalBitwise public static void Main string args ushort a 0X005A in binary 0000 0000 0101 1010 ushort b 0x3C5A in binary 0011 1100 0101 1010 0 x a b 0 x a b 0 x a b 0 x a 0 x b Output 5a 3c5a 3c00 ffffffa5 ffffc3a5 Logical Operators as Conditional Logical Operators The logical bitwise operators may also be used as conditional logical operators since they can be applied to boolean operands and return a bool value. Given that a and b represent boolean expressions the logical operators are defined as in Table . Name Notation Meaning Logical NOT a Logical AND a b Logical OR a b Logical XOR a b Returns the complement of the truth value of a negation true if both operands are true otherwise false true if either or both operands are true otherwise false true if and only if one operand is true otherwise false .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.