60.5k views
4 votes
Using the smallest data size possible, either a byte ( 8 bits), a halfword (16 bits), or a word (32 bits), convert the following values into two's complement representations: (i) -18304 (ii) −20 (iii) −128 (iv) −129

1 Answer

2 votes

Answer:

To convert values into two's complement representations using the smallest data size, we'll assume a word size of 8 bits (1 byte). Please note that representing negative numbers using only 8 bits has limitations and might result in overflow or loss of precision for larger values.

(i) -18304:

To represent -18304 in two's complement using 8 bits:

Convert the absolute value of the number to binary: 18304 = 01001001 00000000

Flip all the bits: 10110110 11111111

Add 1 to the flipped bits: 10110111 00000000

The two's complement representation of -18304 in 8 bits is 10110111.

(ii) -20:

To represent -20 in two's complement using 8 bits:

Convert the absolute value of the number to binary: 20 = 00010100

Flip all the bits: 11101011

Add 1 to the flipped bits: 11101011

The two's complement representation of -20 in 8 bits is 11101011.

(iii) -128:

To represent -128 in two's complement using 8 bits:

Convert the absolute value of the number to binary: 128 = 10000000

Flip all the bits: 01111111

Add 1 to the flipped bits: 10000000

The two's complement representation of -128 in 8 bits is 10000000.

(iv) -129:

To represent -129 in two's complement using 8 bits:

Convert the absolute value of the number to binary: 129 = 10000001

Flip all the bits: 01111110

Add 1 to the flipped bits: 01111111

The two's complement representation of -129 in 8 bits is 01111111.

Please note that negative numbers are typically represented using a sign bit and the remaining bits represent the magnitude. The two's complement is one way to represent negative numbers in binary, but it is not the only method. Additionally, using larger data sizes like a half-word (16 bits) or a word (32 bits) allows for representing a wider range of numbers without overflow or precision issues.

User Taghi Khavari
by
8.3k points

No related questions found