Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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
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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top