Or, if you just need a super-fast approximation for a PIC 16C7x or similar (in assembly) Byte/2 - Byte/8 with all remainders dropped: bcf STATUS,C rrf BYTE,w ;128=100% movwf PERCENT swapf BYTE,W movwf TEMP bcf STATUS,C rlf TEMP,W andlw 0x1F subwf PERCENT,F Example: Byte = 0x80 (128) divide by 2: 0x40 (64) swap into TEMP, rotate left, and erase high 3 bits. TEMP=0x0E (14) Subtract this value from percent: 0x32 (50%) Not all values work out this nicely, but it will be close ---------- > From: Keith Howell > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: Conversion of byte to percentage > Date: Thursday, May 21, 1998 8:53 AM > > adrian aslett wrote: > > > > I have a need to convert a byte value into a percentage. > > By coincidence, I have to do the exact same thing > to show a quantity (0-255) on a display of 0-99 bars. > > unsigned char cByte; > unsigned int nPercent; > > nPercent = (((int)cByte)*100)/256; > > and the division by 256 is identical to >>8, > or just take the high byte. > 0--> 0, > 255 -> 99.