[SOLVED] shifting of negative number in PIC MCU's

Status
Not open for further replies.

ashugtiwari

Full Member level 4
Joined
Dec 12, 2008
Messages
218
Helped
45
Reputation
90
Reaction score
44
Trophy points
1,308
Visit site
Activity points
3,310
Hi all,
in one of my project, im doing some division operation on negative numbers, which is division by 2 and 4 mostly, so when i use right shift for division or left shift for multiplication, will the sign persist? or do i have to chk sign before and after operation and make adjustments?

Im using PIC16F1937 8 bit MCU and MPLAB X, plz reply

thanks
Ashutosh
 

In general: yes, the sign is preserved. It's worth checking the documentation (once) for the particular compiler/assembler/device instruction set you're using, but don't add code to test at run time

 
Hi thylacine1975,
thanks for the answer. you r right, it preserves the sign, the compiler uses arithmetic shift instruction for signed numbers.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…