Last Updated: February 25, 2016
·
10.72K
· tomgco

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)

2 Responses
Add your response

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
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