Help in formatting Binary counter for LCD display.

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Francesco.C
Posts: 41
Joined: Thu Feb 26, 2009 6:54 pm
Location: UK

Help in formatting Binary counter for LCD display.

Post by Francesco.C » Tue Jun 30, 2009 8:13 pm

Hi guys,

I am using the commad: BinToStr(Number) to output a binary number to an
LCD display.

The problem is this.

Say I want to display a binary number (8bits) counting from 0 to 127, the LCD display will show nothing when the count is zero.

Then, as the counter increments , will show '1' and no zeros.
Then will whow '101, and no trailing zero. And so on!

Any idea of how to output a whole 8bit number, and change it as the counter increments?


Regards

Francesco C.

MattH
Registered User
Registered User
Posts: 51
Joined: Mon Jan 01, 2007 8:03 pm
Location: Allentown, PA

Post by MattH » Wed Jul 01, 2009 2:18 am

From the help file:



function BinToStr(pValue as type [, pPad as byte, pPadChar as char = "0"]) as string

pValue - The number to convert. The argument can be of type byte, shortint, word, integer, longword or longint.

pPad - An optional parameter which will pack the left hand side of the returned string with (pPad - length of numeric string) zeros.

pPadChar - An optional parameter which changes the default packing character.

This function will convert a number and return a string binary representation of the number passed. Optional pPad and pPadChar arguments can be used to format the returned string value. For example,



MyString = BinToStr(12) // result is "1100"

MyString = BinToStr(12,5) // result is "01100"

MyString = BinToStr(12,5,"#") // result is "#1100"

Francesco.C
Posts: 41
Joined: Thu Feb 26, 2009 6:54 pm
Location: UK

Post by Francesco.C » Wed Jul 01, 2009 4:47 pm

I feel stupid. :oops:

I should have known that. I have used it before.

Thanks.

Francesco C.

Post Reply