Need help with interview question

Status
Not open for further replies.

ManUtd_Vik

Newbie level 2
Joined
Feb 23, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
San Jose, CA
Visit site
Activity points
14
How to implement i - 8 (8 bit length) ?

I answered that I would use a subtractor (modified adder) to construct carry skip or save or similar adder. He refused to accept it. Please help.

Thanks!
 

converting 8 to binary we get 1000. this means the lower 3 bits of the answer is going to be the lower 3 bits of i,no matter what. So you can instead use a 5 bit subtractor that does(i>>3) - 1 which is going to be a lot simpler and saves area, power and has higher speed. Whould this be a good answer?
 


if you mean by i>>3 shift right by three ... should work ... will try and get back to you

Thanks legendkiller
 

Example: I = 0xAA = b10101010 = 170

Shift 1 place right = 0x55 = b01010101 = 85
Shift 1 place right = 0x2A = b00101010 = 42
Shift 1 place right = 0x15 = b00010101 = 21
Subtract 1 = 0x14 = b00010100 = 20

Clearly subtracting 8 from 170 does not result in 20 so (i >> 3) - 1 does not work. It gives (i/8)-1 not 1-8.

The correct answer is to subtract 8 or add 0xF8, ignoring that a carry will be generated.

Brian.
 

@betwixt
actually the lower 3 bits of i are directly routed to the lower 3 bits of the answer hence you get 10100 from the 5 bit subtractor and 010 from the input i and concatinating it yields 10100010 which is 162. subtracting 8 is the actual answer but why use a full 8 bit subtractor when the lower 3 bits are going to depend on the lower 3 bits of i?

@ManUtd_Vik
you don't need a dedicated shifter circuit. the upper 5 bits can directly be roued to a 5 bit subtractor with the other input set to 1
 
Last edited:

Although the lower three bits are the same, the answer is correct ONLY if the original value is >= 8. An 8-bit subtractor will indicate a 'borrow' occurred to show the number has turned negative, a 5 bit subtractor will not do that.

Brian.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…