Question

pseudo code c Explain how you add fixed-width digits in a decimal number system. How do...

pseudo code c

  • Explain how you add fixed-width digits in a decimal number system.
    • How do you do this in binary?
    • How do you do this in hexadecimal?
  • Explain how you subtract numbers in digits in a decimal number system.
    • How do you do this in binary?
    • How do you do this in hexadecimal?

Homework Answers

Answer #1

Example 63 (x)+ 89 (y) => 52 (sum) and carry=1

Add fixed-width decimal integers; N digits.

1:  carry ← 0 //initiliazzed caarry as 0
2:  for i = 0 to N // i-th bit
3:   sumi ← (xi + yi + carry) % 10 // mod operation if we add 9+3 then sum(i) will be (9+3)%10=2
4:   carry ← (xi + yi + carry) ∕ 10 //div operation carry=(9+3)/10=1
5:  end for //end loop

Add fixed-width binary integers; N bits.

1:  carry ← 0
2:  for i = 0 to N // i-th bit
3:   sumi ← (xi + yi + carry) % 2 // mod operation
4:   carry ← (xi + yi + carry) ∕ 2 // division operation
5:  end for

Add fixed-width integers in hexadecimal; N digits.

1:  carry ← 0
2:  for i = 0 to N − 1 // i-th digit
3:   sumi ← (xi + yi + carry) % 16 //mod
4:   carry ← (xi + yi + carry) ∕ 16 //division
5:  end for

Subtract fixed-width decimal integers; N digits.

1:  borrow ← 0
2:  for i = 0 to N − 1 do // i-th digit
3:   if yi ≤ xi then //subtract Y from X
4:   differencei ← (xi − yi)
5:   else if i = N − 1 then
6:   borrow ← 1 // Result will be wrong!
7:   xi ← xi + 10
8:   differencei ← (xi − yi)
9:   else
10:   j ← i + 1
11:   while xj = 0 do
12:   j ← j + 1
13:   end while
14:   xj ← xj − 1
15:   j ← j − 1
16:   while j > i do
17:   xj ← xj + 10 − 1
18:   j ← j − 1
19:   end while
20:   differencei ← (10+ xi − yi)
21:   end if
22:  end for

Subtract fixed-width binary integers; N digits.

1:  borrow ← 0
2:  for i = 0 to N − 1 do // i-th digit
3:   if yi ≤ xi then //subtract Y from X
4:   differencei ← (xi − yi)
5:   else if i = N − 1 then
6:   borrow ← 1 //Result will be wrong!
7:   xi ← xi + 2 // if we subtract 1 from 0 we cannot so we have to take borrow from left side now //will be 0+(2 if binary ,10 for decibal and 16 for hexadecimal)
8:   differencei ← (xi − yi)
9:   else
10:   j ← i + 1
11:   while xj = 0 do
12:   j ← j + 1
13:   end while
14:   xj ← xj − 1
15:   j ← j − 1
16:   while j > i do
17:   xj ← xj + 2− 1
18:   j ← j − 1
19:   end while
20:   differencei ← (2+ xi − yi)
21:   end if
22:  end for

Subtract fixed-width hexadecimal integers; N digits.

1:  borrow ← 0
2:  for i = 0 to N − 1 // i-th digit
3:   if yi ≤ xi then //subtract Y from X
4:   differencei ← (xi − yi)
5:   else if i = N − 1 then
6:   borrow ← 1 //Result will be wrong!
7:   xi ← xi + 16
8:   differencei ← (xi − yi)
9:   else
10:   j ← i + 1
11:   while xj = 0 do
12:   j ← j + 1
13:   end while
14:   xj ← xj − 1
15:   j ← j − 1
16:   while j > i do
17:   xj ← xj + 16 − 1
18:   j ← j − 1
19:   end while
20:   differencei ← (16 + xi − yi)
21:   end if
22:  end for

if my answer help you then please upvote me.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Explain how you add fixed-width digits in a decimal number system. How do you do this...
Explain how you add fixed-width digits in a decimal number system. How do you do this in binary? How do you do this in hexadecimal? Explain how you subtract numbers in digits in a decimal number system. How do you do this in binary? How do you do this in hexadecimal?
1-What is the decimal number of the binary numbers (101111)2? 2-What is 123 in BCD code?...
1-What is the decimal number of the binary numbers (101111)2? 2-What is 123 in BCD code? 3-Convert the binary (10101011101)2 into octal and hexadecimal? 4-What is 2's complement of (1101110)2? 5-Convert the decimal number 152.25 into binary?
5) Using a minimum number of digits, what is the encoding for the decimal value 139?...
5) Using a minimum number of digits, what is the encoding for the decimal value 139? a) As an unsigned binary value b) As a BCD binary value c) As a 7 segment code binary value
In C++ Write a program that will convert a string of binary digits to their decimal...
In C++ Write a program that will convert a string of binary digits to their decimal equivalent. For convenience limit the binary number to 16 bits. Write the decimal equivalent to the screen. For this program you must read in the binary number as a string type. If you were to enter a large binary number like 110110001100111 as a decimal value it would be too large to fit in an int type.
Directions: Convert the following problems below to c++ equivalent code Problem 6: Get a random number...
Directions: Convert the following problems below to c++ equivalent code Problem 6: Get a random number from the user Remember the original number Add 3 to the number Double the number and then multiply by Knock off the last digit (remove the 1’s place) Finally remove the original number What is the result? Problem 7: 1: Have the person write down any three digits number with decreasing digits (432 or 875). 2: Reverse the number you wrote in #1. 3:...
Hello, I am trying to do an assignment that requires writing an MSP432 code to add...
Hello, I am trying to do an assignment that requires writing an MSP432 code to add two 64 bit numbers together and store the result in memory location 0x2000_0000. The problem is that the it is a 32 bit register. I don't know how to add to a load 64 bit numbers. The question is below but please feel free to use your own examples, I will understand better. Thank you very much. Write a small MSP432 code segment that...
Write the message, “Hello World” in ASCII code. [D: Decimal, B: Binary] can you explain how...
Write the message, “Hello World” in ASCII code. [D: Decimal, B: Binary] can you explain how to go about this really trying to understand
Random number generator 1: Search for algorithms generating pseudo-random numbers. Select one of them for generating...
Random number generator 1: Search for algorithms generating pseudo-random numbers. Select one of them for generating a pseudo-random sequence. Original sample can be generated in any form: binary, decimal, etc. But submitted sample must be in the form of uniform random numbers on [0,1][0,1]. The sample should not be generated by any function, like runif(), sample(), etc. Instead it must be some algorithm that you code yourselves. For example, mid-square algorithm, Fibonacci-based algorithm, etc. Random number generator 2: Find some...
Find the 2's complement of the following decimal numbers (You must convert the number to binary...
Find the 2's complement of the following decimal numbers (You must convert the number to binary and the answer has to be in binary with the same number of bits as the conversion)? a. 20 b. 15 c. 2126 d. 266 e. 466 please explain how you did it!
GI, Nervous and GU system discussion 1. How do you code for ERCPs? explain in detail,...
GI, Nervous and GU system discussion 1. How do you code for ERCPs? explain in detail, give an example. 2. When do you use a mesh when coding a hernia repair? Explain and give an example 3. Explain the endoscopic procedures that can be performed in the GU system.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT