bit_and.carbon 621 B

123456789101112131415161718192021222324252627
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // CHECK:STDOUT: 5
  7. // CHECK:STDOUT: 4
  8. // CHECK:STDOUT: 0
  9. // CHECK:STDOUT: result: 0
  10. package ExplorerTest api;
  11. class A { var n: i32; }
  12. external impl A as BitAndWith(i32) where .Result = A {
  13. fn Op[self: Self](rhs: i32) -> A { return {.n = self.n & rhs}; }
  14. }
  15. fn Main() -> i32 {
  16. var a: A = {.n = 13};
  17. a = a & 7;
  18. Print("{0}", a.n);
  19. a &= -2;
  20. Print("{0}", a.n);
  21. Print("{0}", (a & 3).n);
  22. return 0;
  23. }