Solved

A conversion question (Integer to BCD-string to byte)

Posted on 2003-12-03
5
1,321 Views
Last Modified: 2010-04-05
Hi all,

I'm currently stuck on a small problem....I know the solution should not be too hard to come by, but I just can't figure it out....

I'm working on an application that communicates with a piece of hardware through the serial port. The communication's up and running, no problems there. There is one problem though, I need to be able to set the time and date of the hardware, and the hardware expects that in bcd (binary coded decimal). The communication expects bytes.

I've written a conversion function, that takes an integer value, and returns a string, which contains a two-digit bcd code. What I want is to convert that string to a byte, and send that byte to the serialport, without any more calculation, to be sure I don't lose the bcd value.

If anyone can think of a better way, I'd love to hear it, this is getting silly!

In my opinion it should be possible to just create a byte out of the two sets of 4 bits the bcd code is made up of, but I'm creating my own blind spots or something...

Binsky


0
Comment
Question by:Binsky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 1

Expert Comment

by:wilmsoft
ID: 9868099
I don't understand yet what you want... So, you've done this:

LowBCD.Text := IntToHex(Display,4);


to get the BCD... Now you need which byte?
0
 
LVL 1

Author Comment

by:Binsky
ID: 9872843
Hi,

Actually, what I've done is this :

function TSetupForm.IntToBCD(Value : integer) : string;
begin
   Result := IntToHex(Value div 10, 1) +IntToHex(Value mod 10, 1);
end;

Now I've got a string containing the BCD translation of any integer, but what I want to have is one byte containing the same info...

Binsky
0
 
LVL 1

Author Comment

by:Binsky
ID: 9902341
Okay,

I've answered the question myself...

The conversion is :

BCD := ((16*(DecimalValue div 10)) + (DecimalValue mod 10));
DEC := ((10*(BCDValue div 16))      + (BCDValue mod 16));

Binsky

(Do I get the points myself?) ;-)
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9931963
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question