shift.carbon 866 B

123456789101112131415161718192021222324252627282930313233
  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. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: 8
  9. // CHECK:STDOUT: 4
  10. // CHECK:STDOUT: result: 0
  11. package ExplorerTest api;
  12. fn Main() -> i32 {
  13. if (not (1 << 0 == 1)) { return 1; }
  14. if (not (1 << 3 == 8)) { return 2; }
  15. if (not (0 << 3 == 0)) { return 3; }
  16. if (not (3 << 1 == 6)) { return 4; }
  17. if (not (-1 << 2 == -4)) { return 5; }
  18. if (not (1 >> 0 == 1)) { return 6; }
  19. if (not (1 >> 1 == 0)) { return 7; }
  20. if (not (3 >> 1 == 1)) { return 8; }
  21. if (not (-1 >> 1 == -1)) { return 9; }
  22. if (not (-2 >> 1 == -1)) { return 10; }
  23. var n: i32 = 1;
  24. n <<= 3;
  25. Print("{0}", n);
  26. n >>= 1;
  27. Print("{0}", n);
  28. return 0;
  29. }