Skip to content

Instantly share code, notes, and snippets.

@smcveigh-phunware
Last active October 17, 2017 17:31
Show Gist options
  • Save smcveigh-phunware/e5136ad7289183663acee047a312bdf7 to your computer and use it in GitHub Desktop.
Save smcveigh-phunware/e5136ad7289183663acee047a312bdf7 to your computer and use it in GitHub Desktop.
2's compliment
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def twos(x:int) -> int:
assert x in range(256), "x is not an unsigned byte"
return x-256 if x > 0x7F else x
repr(list(map(twos, range(256))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment