Ulong conversion.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Roy Johnston
Flowcode V4 User
Posts: 220
Joined: Mon Aug 24, 2009 8:38 am
Has thanked: 2 times
Been thanked: 34 times
Contact:

Ulong conversion.

Post by Roy Johnston »

can someone help me to do the following.

1) convert a Ulong into a byte array.
2) convert a byte array to an Ulong.
3) convert a Ulong into a byte array in VB
4) convert a byte array to an Ulong in VB.

on another Note,
I am a NGO sponsor for the Dewildt Cheetah Farm IN bela bela South Africa.
I also run it for Ann Van Dyk.
http://www.dewildt.co.za/index.php?opti ... &Itemid=65
this center is the leading center in the world on cheetah ,
the farm is also an un-spoilt conservation farm.

as a token of my appreciation for all the help from Flowcode Staff,
if any of the matrixmultimedia staff find them in south Africa, I would lie to offer them a week free holiday here on the farm.

Regards
Roy Johnston

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Ulong conversion.

Post by Benj »

Hi Roy,

I can help with 1 and 2 but VB is not my strong point.

As for staying at the farm sounds like a fantastic opportunity, thanks for the offer. Unfortunately I've already booked my holiday/honeymoon to Kenya this year, knew I should have waited :wink:


1) convert a Ulong into a byte array.

Code: Select all

byte[0] = Long
byte[1] = Long >> 8
byte[2] = Long >> 16
byte[3] = Long >> 24
There may be issues on 8-bit devices for the 16 and 24 bit shifts, in C you would perform a typecast but even this has issues. In Flowcode we have added a structure to allow you to do this but unfortunately you need to resort to using C at the moment so it won't simulate etc. We should be able to make this a supported function fairly easily, I'll add it to the list.

Code: Select all

MX_Union32 LongToByte;

LongToByte.AsLong = FCV_LONGVAR;

FCV_BYTE[0] = LongToByte.AsByte[0];
FCV_BYTE[1] = LongToByte.AsByte[1];
FCV_BYTE[2] = LongToByte.AsByte[2];
FCV_BYTE[3] = LongToByte.AsByte[3];
2) convert a byte array to an Ulong.

Code: Select all

Long = byte[0]
Long = Long | byte[1] << 8
Long = Long | byte[2] << 16
Long = Long | byte[3] << 24
Again there may be issues on 8-bit devices for the 16 and 24 bit shifts so here is the C code that is known to work.

Code: Select all

MX_Union32 LongToByte;

LongToByte.AsByte[0] = FCV_BYTE[0];
LongToByte.AsByte[1] = FCV_BYTE[1];
LongToByte.AsByte[2] = FCV_BYTE[2];
LongToByte.AsByte[3] = FCV_BYTE[3];

FCV_LONGVAR = LongToByte.AsLong;

Roy Johnston
Flowcode V4 User
Posts: 220
Joined: Mon Aug 24, 2009 8:38 am
Has thanked: 2 times
Been thanked: 34 times
Contact:

Re: Ulong conversion.

Post by Roy Johnston »

Thanks for your help,

Post Reply