t21564.nim 575 B

123456789101112131415161718192021222324252627282930313233
  1. discard """
  2. targets: "c js"
  3. """
  4. import bitops
  5. import std/assertions
  6. proc main() =
  7. block: # bug #21564
  8. # tesk `bitops.bitsliced` patch
  9. doAssert(0x17.bitsliced(4..7) == 0x01)
  10. doAssert(0x17.bitsliced(0..3) == 0x07)
  11. block:
  12. # test in-place `bitops.bitslice`
  13. var t = 0x12F4
  14. t.bitslice(4..7)
  15. doAssert(t == 0xF)
  16. block:
  17. # test `bitops.toMask` patch via bitops.masked
  18. doAssert(0x12FFFF34.masked(8..23) == 0x00FFFF00)
  19. block: # bug #22687
  20. var a: uint8 = 0b1111_1111
  21. doAssert a.bitsliced(4..7).int == 15
  22. main()
  23. static:
  24. main()