File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ extension BitWriter {
5252 }
5353
5454 public func write( number: Int , bitsCount: Int ) {
55+ precondition ( 0 ... Int . bitWidth ~= bitsCount)
5556 self . write ( unsignedNumber: UInt ( bitPattern: number) , bitsCount: bitsCount)
5657 }
5758
Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ public final class LsbBitWriter: BitWriter {
5050 thus, crashes when converting to an `Int` if `write(number:bitsCount:)` method is used.
5151 */
5252 public func write( unsignedNumber: UInt , bitsCount: Int ) {
53- var mask : UInt = 1
53+ precondition ( 0 ... UInt . bitWidth ~= bitsCount)
54+ var mask = 1 as UInt
5455 for _ in 0 ..< bitsCount {
5556 self . write ( bit: unsignedNumber & mask > 0 ? 1 : 0 )
5657 mask <<= 1
Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ public final class MsbBitWriter: BitWriter {
5050 thus, crashes when converting to an `Int` if `write(number:bitsCount:)` method is used.
5151 */
5252 public func write( unsignedNumber: UInt , bitsCount: Int ) {
53- var mask : UInt = 1 << ( UInt ( truncatingIfNeeded: bitsCount) - 1 )
53+ precondition ( 0 ... UInt . bitWidth ~= bitsCount)
54+ var mask = ( 1 as UInt ) << ( bitsCount - 1 )
5455 for _ in 0 ..< bitsCount {
5556 self . write ( bit: unsignedNumber & mask > 0 ? 1 : 0 )
5657 mask >>= 1
You can’t perform that action at this time.
0 commit comments