Board index » delphi » How to convert extended ASCII to Binary ?

How to convert extended ASCII to Binary ?

I am writing a program (D4) to control a  ham radio through the serial
port using AsyncPro.  The radio allows me to send it a 5 byte poling
code and then immediately responds by sending a one (1) byte response
that indicates the status of the receiver or the transmitter.  

Here's the problem:

I can send the poling code and the radio responds by sending the 1
byte back (a numeric value from 00-255 or 00h-FFh).  However in order
to interpret the status I must be able to display the byte in hex
format.  

Ex: byte value 26 = 1A Hex = 0001 0110 binary
      Smiley Face = 0000 0011 binary

Each bit in the byte gives me an off-on value that I can interpret to
indicate various things about the radio's staus (Squelch, Frequency,
etc).

If, using asyncpro, I place the returned data in an edit box I always
end up displaying something like a smiley face or a male symbol etc.
Apparently the  the byte is being interpreted for display purposes
according to the extended ASCII chart.

What I need to do is either convert the data as received from the
comport to binary format and then display the string of 8 zeros or
ones in the text box or take the character in the edit box and convert
it to binary and then display it in another edit box.

Available procedures in Async pro to retrieve data  include:

procedure TForm1.ApdDataPacket1StringPacket(Sender: TObject; Data:
String);

procedure TForm1.ApdDataPacket1Packet(Sender: TObject; Data: Pointer;
  Size: Integer);

I've been through all my Delphi 4 manuals and the help files and
cannot seem to find an obvious way to do this.

Any help would be appreciated!

Dave Alden   d-al...@concentirc.net

 

Re:How to convert extended ASCII to Binary ?


One way to convert decimal to binary is as follows (Back in my school days
anyway...):

Take the number eg 165.
Divide 165 by 2 = 82   remainder = 1
divide 82 by 2 = 41  remainder = 0
divide 41 by 2 = 20  remainder = 1
divide 20 by 2 = 10  remainder = 0
divide 10 by 2 = 5  remainder = 0
divide 5 by 2 = 2  remainder = 1
divide 2 by 2 = 1  remainder = 0
divide 1 by 2 = 0  remainder = 1

thus the binary value = 1010 0101 (reading the remainders from the bottom)

Danie

Quote
Dave Alden <d-al...@concentric.net> wrote in message

news:37a1bb45.8101156@news.concentric.net...
Quote

> I am writing a program (D4) to control a  ham radio through the serial
> port using AsyncPro.  The radio allows me to send it a 5 byte poling
> code and then immediately responds by sending a one (1) byte response
> that indicates the status of the receiver or the transmitter.

> Here's the problem:

> I can send the poling code and the radio responds by sending the 1
> byte back (a numeric value from 00-255 or 00h-FFh).  However in order
> to interpret the status I must be able to display the byte in hex
> format.

> Ex: byte value 26 = 1A Hex = 0001 0110 binary
>       Smiley Face = 0000 0011 binary

> Each bit in the byte gives me an off-on value that I can interpret to
> indicate various things about the radio's staus (Squelch, Frequency,
> etc).

> If, using asyncpro, I place the returned data in an edit box I always
> end up displaying something like a smiley face or a male symbol etc.
> Apparently the  the byte is being interpreted for display purposes
> according to the extended ASCII chart.

> What I need to do is either convert the data as received from the
> comport to binary format and then display the string of 8 zeros or
> ones in the text box or take the character in the edit box and convert
> it to binary and then display it in another edit box.

> Available procedures in Async pro to retrieve data  include:

> procedure TForm1.ApdDataPacket1StringPacket(Sender: TObject; Data:
> String);

> procedure TForm1.ApdDataPacket1Packet(Sender: TObject; Data: Pointer;
>   Size: Integer);

> I've been through all my Delphi 4 manuals and the help files and
> cannot seem to find an obvious way to do this.

> Any help would be appreciated!

> Dave Alden   d-al...@concentirc.net

Other Threads