ttouintconv.nim 983 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import macros
  2. discard """
  3. nimout: '''
  4. 8 9 17
  5. 239 255
  6. 61439 65534 65535
  7. 4026531839 4294967294
  8. 17293822569102704639
  9. 18446744073709551614
  10. 18446744073709551615
  11. 127
  12. 32767
  13. 2147483647
  14. 9223372036854775807
  15. 0
  16. 128
  17. 4294967287'''
  18. """
  19. #bug #2514
  20. macro foo() =
  21. var x = 8'u8
  22. var y = 9'u16
  23. var z = 17'u32
  24. echo x," ", y," ", z
  25. var a = 0xEF'u8
  26. var aa = 0xFF'u8
  27. echo a, " ", aa
  28. var b = 0xEFFF'u16
  29. var bb = 0xFFFE'u16
  30. var bbb = 0xFFFF'u16
  31. echo b, " ", bb, " ", bbb
  32. var c = 0xEFFFFFFF'u32
  33. var cc = 0xFFFFFFFE'u32
  34. echo c, " ", cc
  35. var d = 0xEFFFFFFFFFFFFFFF'u64
  36. echo d
  37. var f = 0xFFFFFFFFFFFFFFFE'u64
  38. echo f
  39. var g = 0xFFFFFFFFFFFFFFFF'u64
  40. echo g
  41. var xx = 0x7F'u8 and 0xFF
  42. echo xx
  43. var yy = 0x7FFF'u16
  44. echo yy
  45. var zz = 0x7FFFFFFF'u32
  46. echo zz
  47. macro foo2() =
  48. var xx = 0x7FFFFFFFFFFFFFFF
  49. echo xx
  50. var yy = 0
  51. echo yy
  52. var zz = 0x80'u8
  53. echo zz
  54. var ww = -9
  55. var vv = cast[uint](ww)
  56. var kk = cast[uint32](vv)
  57. echo kk
  58. foo()
  59. foo2()