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.

How to convert 2's complement binary value into actual decimal value

Status
Not open for further replies.

Ganesh singh

Newbie level 5
Joined
Jan 23, 2010
Messages
10
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Banglore
Activity points
1,379
Hi everybody,
My sensor output is 2,s complement ( to handle the negative values) . so now i have to show the result in decimal with proper sign.

can anybody help me in this ....
i am using Hitech C. and my microcontroller is PIC16F1783.
 

Once you have obtained a positive binary value...

Count how many times you can subtract a power of ten. If your number is, say 3456, then subtract 1000. Each time you do, increment a counter.

When you can't subtract 1000 any more, start subtracting 100. Start the next counter, incrementing each time.

Etc.

Until you reach 0.

Convert the stored count values to ASCII numerals. Print them one after the other. The first character should be a plus or minus sign, based on whether your initial value had a 1 in the most significant bit position.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top