## Converting data types

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

JAW
Posts: 30
Joined: Tue Jun 16, 2009 2:25 pm
Been thanked: 4 times
Contact:

### Converting data types

I'm having trouble being able to convert to decimal values into a hex value to send to a dallas time chip. I'm trying to write code for a clock with a menu enabelling you to change the time. The display shows the decimal value but I can't get my head round converting to hex and then sending down the I2C. Any help would be greatly appreciated.

Regards

James

Benj
Matrix Staff
Posts: 14075
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4297 times
Been thanked: 4051 times
Contact:

### Re: Converting data types

Hello James,

First use the string manipulation function toString to convert the number in to an ascii string. Once you have done this you can send the string by referencing the string as a byte array.

eg

stringvar = toString(123)

i2csend (stringvar[0])
i2csend (stringvar[1])
i2csend (stringvar[2])

JAW
Posts: 30
Joined: Tue Jun 16, 2009 2:25 pm
Been thanked: 4 times
Contact:

### Re: Converting data types

Hi Benj,

Thank you for your reply. I'm trying to go down the route of converting the decimal value to a bcd code. So far I've found a previous post but can't get it to workk correctly :-

dec_t = dec/10
dec_u = dec MOD 10
bcd = (dec_u << 4)
bcd = bcd + dec_u

dec is the original decimal value
dec_t and dec_u are temporary values
bcd is the final final value

Regards

James

medelec35
Valued Contributor
Posts: 8294
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2373 times
Been thanked: 3380 times
Contact:

### Re: Converting data types

Hello JAW.
Try chaging bcd = (dec_u << 4)
to
bcd = (dec_t << 4)

So you have:
dec_t = dec/10
dec_u = dec MOD 10
bcd = (dec_t << 4)
bcd = bcd + dec_u

Hope this helps.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JAW
Posts: 30
Joined: Tue Jun 16, 2009 2:25 pm
Been thanked: 4 times
Contact:

### Re: Converting data types

Thanks Medelec that's working perfectly now.

Many Thanks

James