Skip to content

Instantly share code, notes, and snippets.

@JeOam
Last active March 25, 2021 15:21
Show Gist options
  • Save JeOam/b2b417e357480cf137c5 to your computer and use it in GitHub Desktop.
Save JeOam/b2b417e357480cf137c5 to your computer and use it in GitHub Desktop.
Bool Algebra in Computer Science

Except from Computer Systems: A Programmer's Perspective, Second Edition.

@JeOam
Copy link
Author

JeOam commented Oct 11, 2015

For “binary(B) to unsigned(U),” length w:

screen shot 2015-10-11 at 11 47 53 am

@JeOam
Copy link
Author

JeOam commented Oct 11, 2015

For “binary(B) to two’s-complement(T)” length w:

screen shot 2015-10-11 at 11 51 50 am

@JeOam
Copy link
Author

JeOam commented Oct 11, 2015

A signed number x and its unsigned counterpart:

screen shot 2015-10-11 at 12 01 31 pm

Accordingly:
screen shot 2015-10-11 at 12 03 50 pm

@JeOam
Copy link
Author

JeOam commented Oct 11, 2015

An unsigned number u and its signed counterpart:

screen shot 2015-10-11 at 12 07 08 pm

Accordingly:

screen shot 2015-10-11 at 12 08 54 pm

@JeOam
Copy link
Author

JeOam commented Oct 11, 2015

When truncating a w-bit number to a k-bit number, we drop the high-order w−k bits. The effect of truncation for unsigned numbers is:

screen shot 2015-10-11 at 12 13 08 pm

while the effect for two’s-complement numbers is:

screen shot 2015-10-11 at 12 13 49 pm

@JeOam
Copy link
Author

JeOam commented Oct 11, 2015

Performing addition on two w-bit unsigned values:

screen shot 2015-10-11 at 5 57 40 pm

Performing addition on two w-bit two’s-complement values:

screen shot 2015-10-11 at 6 34 34 pm

@JeOam
Copy link
Author

JeOam commented Oct 11, 2015

The inverse of unsigned value x:

screen shot 2015-10-11 at 6 03 09 pm

Two’s-Complement Negation:

screen shot 2015-10-11 at 6 35 50 pm

@JeOam
Copy link
Author

JeOam commented Oct 12, 2015

The effect of the w-bit unsigned multiplication operation e990a822-a5aa-4467-baa4-c2ef0df38c5d is:

09215867-1fcc-42bb-9ad5-249dbaa37560

The effect of the w-bit two’s-complement multiplication operation 915137fa-cd0e-4e28-a485-4fc34c9e707f is:

48669be9-f8b0-46f4-9831-35510d97bc16

Note: the low-order bits of the two products (unsigned and two’s complement) are identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment