binary to decimal

Status
Not open for further replies.

peterzatko

New Member
I need help how can i convert 8 bit binary word(11111111) to decimal(255).

for Example:

I have 8 inputs (but not all are on the same port(A,B,C)- two inputs are on portc four are on porta and other are on portb ).


PLease help me.I really dont know how to make it.I use mikrobasic

thx
 
hi,
You have not stated the 'weighting' of the individual Bits.?

For example, consider the 4 bits on PORTC.
If they were representing the 4 most significant bits within the final Byte and their pins were say D3,2,1,0 you could AND the PORTC value with 0x0F, then left shift the AND'd value 4 times. That would place the 4 most significant bits at D7,6,5,4.

Repeat the above for the other two PORTs, using a suitable AND'ing value and shifts.

You will then have 3 registers with the Bits in their correct weighting positions, then OR the registers to give the final Byte.

Look at Nigels tutorial link near my signature on this post for an example of a 8 Bit to Decimal subroutine
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…