2's Complement in Javascript
My message to checksum:
var d = 0x0a + 0x80 + 0x04 + 0x06 + 0x20 + 0xff + 0xff
Represented as Base 16:
(~d + 1 >>> 0).toString(16)
or Binary:
(~d + 1 >>> 0).toString(2)Written by Tom Gallacher
Related protips
2 Responses
This should have more likes, reminding me of good ol' times at CS 101.
over 1 year ago
·
Perfect for UPB command checksums!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Checksum
Authors
tomgco
10.72K
trinitronx
5.238K
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#