Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider a 32 bit binary number system that represents negative numbers using 2\

ID: 673911 • Letter: C

Question

Consider a 32 bit binary number system that represents negative numbers using 2's complements, like that we discussed in the class. To speed up our operations with the numbers we use their hexadecimal representation instead of the binary one. In this case a 32 bit integer will be represented with an 8-digit hexadecimal number.

a) Define an algorithm for computing the negation of an 8-digit hexadecimal number which produces the same result that is produced by the 2's complement negation on the corresponding 32-bit binary numbers. For instance, if x is 0000FACE , then –x is FFFF0532

Your algorithm must work directly with the hexadecimal representation of the numbers without expanding them into their binary form.

b) Using your algorithm, compute the negations of the following hexadecimal numbers. For each case you MUST show all the steps of your calculations and not just the final result.

00FACADE

80000000

FFFFFFFF

Explanation / Answer

Answer:

Input: 8-digit hexadecimal number:hexNumber

Output: negation of 8-digit hexadecimal number:neghexNum

            Step 1:Get the hexadecimal number

Step 2:Take digit by digit. For each digit in the hexadecimal number

Step 2.1: convert the digit to decimal (hexadecimal to decimal for each digit) and   store it in decNum

Step 2.2:find the decValue =15- decNum

Step 2.3then convert the decValue to hexadecimal & store it in neghexNum (decimal to hexadecimal)

            Step 3:print neghexNum.

Pseudocode: complementHexadecimal(hexNum,neghexNum)

i=0;

while hexNumber!=’’ do

If hexNumber[i]>=48&& hexNumber[i]<=57 do

            decNum=hexNumber[i]-48;

end if

else if hexNumber[i]>=65 && hexNumber[i]<=70 do

            decNum=hexNumber[i]-55;

end elseif

find decValue=(15-decNum)

if decValue >=0 and decValue <=9 then do

neghexNum[i]=( decValue +48);

            end if

else if decValue =10 then do

neghexNum[i]=’A’;

            end if

else if decValue =11 then do

neghexNum[i]=’B’;

end if

else if decValue =12 then do

neghexNum[i]=’C’;

end if

else if decValue =13 then do

neghexNum[i]=’D’;

end if

else if decValue =14 do

neghexNum[i]=’E’;

end if

else if decValue =15 do

neghexNum[i]=’F’;

end if

i++;

neghexNum[i]=’’

print the neghexNum

Below is the program written in c language for finding the complement of hexadecimal number

Code:

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

int main()

{

char hexNumber[8]="FFFF0000",neghexNum[8];

int i;

int decNum;

int decValue;

for(i=0; hexNumber[i]!='';i++)

{

if( hexNumber[i]>=48&& hexNumber[i]<=57)

     decNum=hexNumber[i]-48;

else if( hexNumber[i]>=65 && hexNumber[i]<=70)

     decNum=hexNumber[i]-55;

decValue=(15-decNum);

if (decValue >=0 && decValue <=9)

neghexNum[i]=( decValue +48);

else if (decValue ==10 )

neghexNum[i]='A';

else if (decValue==11 )

neghexNum[i]='B';

else if (decValue==12)

neghexNum[i]='C';

else if( decValue ==13 )

neghexNum[i]='D';

else if( decValue ==14)

neghexNum[i]='E';

else if (decValue ==15)

neghexNum[i]='F';

}

neghexNum[i]='';

printf("%s",neghexNum);

getch();

return 0;

}

b.   Find negative hexadecimal complement of 00FACADE

Step 1: store the number in hexNumber=00FACADE

Step 2: take the first digit 0

Step 2.1: convert the digit to decimal .decNum=0

Step 2.2: calculate decValue=15-decNum=15

Step 2.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum;

Step 3: take the nextdigit 0

Step 3.1: convert the digit to decimal .decNum=0

Step 3.2: calculate decValue=15-decNum=15

Step 3.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum;

Step 4: take the nextdigit F

Step 4.1: convert the digit to decimal .decNum=15

Step 4.2: calculate decValue=15-decNum=0

Step 4.3: convert decValue to hexadecimal so we get 0 store it in neghexNum;

Step 5: take the nextdigit A

Step 5.1: convert the digit to decimal .decNum=10

Step 5.2: calculate decValue=15-decNum=5

Step 5.3: convert decValue to hexadecimal so we get 5 store it in neghexNum;

Step 6: take the nextdigit C

Step 6.1: convert the digit to decimal .decNum=12

Step 6.2: calculate decValue=15-decNum=3

Step 6.3: convert decValue to hexadecimal so we get 3 store it in neghexNum;

Step 7: take the nextdigit A

Step 7.1: convert the digit to decimal .decNum=10

Step 7.2: calculate decValue=15-decNum=5

Step 7.3: convert decValue to hexadecimal so we get 5 store it in neghexNum;

Step 8: take the nextdigit D

Step 9.1: convert the digit to decimal .decNum=13

Step 9.2: calculate decValue=15-decNum=2

Step 9.3: convert decValue to hexadecimal so we get 2 store it in neghexNum;

Step 9: take the nextdigit E

Step 9.1: convert the digit to decimal .decNum=14

Step 9.2: calculate decValue=15-decNum=1

Step 9.3: convert decValue to hexadecimal so we get 1 store it in neghexNum;

Finally neghexNum will have the value “FF053521”

Find negative hexadecimal complement of 80000000

Step 1: store the number in hexNumber=80000000

Step 2: take the first digit 8

Step 2.1: convert the digit to decimal .decNum=8

Step 2.2: calculate decValue=15-decNum=7

Step 2.3: convert decValue to hexadecimal so we get 7 store it in neghexNum;

Step 3: take the nextdigit 0

Step 3.1: convert the digit to decimal .decNum=0

Step 3.2: calculate decValue=15-decNum=15

Step 3.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum;

Step 4: take the nextdigit 0

Step 4.1: convert the digit to decimal .decNum=0

Step 4.2: calculate decValue=15-decNum=15

Step4.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum;

Step 5: take the nextdigit 0

Step 5.1: convert the digit to decimal .decNum=0

Step 5.2: calculate decValue=15-decNum=15

Step 5.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum

Step 6: take the nextdigit 0

Step 6.1: convert the digit to decimal .decNum=0

Step 6.2: calculate decValue=15-decNum=15

Step 6.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum

Step 7: take the nextdigit 0

Step 7.1: convert the digit to decimal .decNum=0

Step 7.2: calculate decValue=15-decNum=15

Step 7.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum

Step 8: take the nextdigit 0

Step 8.1: convert the digit to decimal .decNum=0

Step8.2: calculate decValue=15-decNum=15

Step 8.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum

Step 9: take the nextdigit 0

Step 9.1: convert the digit to decimal .decNum=0

Step 9.2: calculate decValue=15-decNum=15

Step 9.3: convert decValue to hexadecimal so we get ‘F’ store it in neghexNum

Finally neghexNum will have the value “7FFFFFFF”

Find negative hexadecimal complement of FFFFFFFF

Step 1: store the number in hexNumber=FFFFFFFF

Step 2: take the first digit F

Step 2.1: convert the digit to decimal .decNum=15

Step 2.2: calculate decValue=15-decNum=0

Step 2.3: convert decValue to hexadecimal so we get 0 store it in neghexNum;

Step 3: take the nextdigit F

Step 3.1: convert the digit to decimal .decNum=15

Step 3.2: calculate decValue=15-decNum=0

Step 3.3: convert decValue to hexadecimal so we get 0 store it in neghexNum;

Step 4: take the nextdigit F

Step 4.1: convert the digit to decimal .decNum=15

Step 4.2: calculate decValue=15-decNum=0

Step4.3: convert decValue to hexadecimal so we get 0 store it in neghexNum;

Step 5: take the nextdigit F

Step 5.1: convert the digit to decimal .decNum=15

Step 5.2: calculate decValue=15-decNum=0

Step 5.3: convert decValue to hexadecimal so we get 0 stores it in neghexNum

Step 6: take the nextdigit F

Step 6.1: convert the digit to decimal .decNum=15

Step 6.2: calculate decValue=15-decNum=0

Step 6.3: convert decValue to hexadecimal so we get 0 stores it in neghexNum

Step 7: take the nextdigit F

Step 7.1: convert the digit to decimal .decNum=15

Step 7.2: calculate decValue=15-decNum=0

Step 7.3: convert decValue to hexadecimal so we get 0 stores it in neghexNum

Step 8: take the nextdigit F

Step 8.1: convert the digit to decimal .decNum=15

Step8.2: calculate decValue=15-decNum=0

Step 8.3: convert decValue to hexadecimal so we get 0 stores it in neghexNum

Step 9: take the nextdigit F

Step 9.1: convert the digit to decimal .decNum=15

Step 9.2: calculate decValue=15-decNum=0

Step 9.3: convert decValue to hexadecimal so we get 0 store it in neghexNum

Finally neghexNum will have the value “00000000”

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote