From b60fe860e0291bbe7b433ccf0e983fa76dabe3cd Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Sat, 16 Aug 2014 11:57:54 +0300 Subject: [PATCH] Fix reading UInt32 In JS, 0x80 << 24 yields a negative result. Also, 0x80000000|0 < 0. Bitwise ops should be avoided for very long unsigned ints. --- lib/data.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/data.coffee b/lib/data.coffee index 75723a3..38db184 100644 --- a/lib/data.coffee +++ b/lib/data.coffee @@ -19,11 +19,11 @@ class Data @writeByte if val then 1 else 0 readUInt32: -> - b1 = @readByte() << 24 + b1 = @readByte() * 0x1000000 b2 = @readByte() << 16 b3 = @readByte() << 8 b4 = @readByte() - b1 | b2 | b3 | b4 + b1 + b2 + b3 + b4 writeUInt32: (val) -> @writeByte (val >>> 24) & 0xff @@ -137,4 +137,4 @@ class Data for byte in bytes @writeByte byte -module.exports = Data \ No newline at end of file +module.exports = Data