Hex to Decimal
Hex to Decimal
How would i go about converting a large Hexidecimal number to Decimal in flowcode
IE. 1400DE15d1
Rgds
Wayne
IE. 1400DE15d1
Rgds
Wayne
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Hex to Decimal
The number you gave equates to a decimal value of 85913900497 and would need 5 bytes to store it (which is beyond Flowcode's current limits).
Another approach you could use it to use Binary Coded Decimal, in which case the conversion is relatively trivial.
Another approach you could use it to use Binary Coded Decimal, in which case the conversion is relatively trivial.
Re: Hex to Decimal
Is it possible to convert the HEX and only store the last 8 digits as i do not need the first 3 (859)
Rgds
Wayne
Rgds
Wayne
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Hex to Decimal
You would still need to perform the full conversion and then disregard the most significant 3 digits. If you explain what you are trying to do, we may be able to offer a better solution.
Re: Hex to Decimal
I am trying use a RFID E-block to read are existing ID cards to log employees into a area and switch on the lights and only switch off the lights when the area is vacated
Using the reader it comes back with the following value from the 1st 5 bytes
20 0 222 21 209
Now to get the employees ID number i would have to convert this to HEX giving
1400DE15D1
then back to Decimal
85913900497
And then the last 8 Digits gives you the Employees number
13900497
Rgds
Wayne
(i have attached the flowcode)
Using the reader it comes back with the following value from the 1st 5 bytes
20 0 222 21 209
Now to get the employees ID number i would have to convert this to HEX giving
1400DE15D1
then back to Decimal
85913900497
And then the last 8 Digits gives you the Employees number
13900497
Rgds
Wayne
(i have attached the flowcode)
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Hex to Decimal
I see. You do need to look at the whole number to get that info. But I can suggest a shortcut plus a potential solution...
First the shortcut - you do not need to convert to hex. If you receive "20 0 222 21 209", then this equals 209 + (21*256) + (222*256*256) + (0*256*256*256) + (20*256*256*256*256) = 85913900497.
Second, a potential solution. Create a byte array of 14 bytes (I'll call this id[14]), then follow this procedure:
1) take the low byte (209) and break it into it's powers of 10 (i.e. 2, 0, and 9) and add these to the id locations id[11], id[12] and id[13]. At this stage, the id variable would contain: 0,0,0,0,0,2,0,9
2) take the next byte (21) and multiply it by 256 (to give 5376). Your holding variable will need to be an integer rather than a byte for this. Add these to the relevant id digits, which would result in "id" as follows: 0,0,0,0,0,0,0,0,0,0,5,5,7,15.
3) now cycle through from id[13] to id[0] and if the number is above 9, take 10 away and add 1 to the next number. This would leave "id" as 0,0,0,0,0,0,0,0,0,0,5,5,8,5.
4) unfortunately, the precision of numbers available within this version of Flowcode now runs out. So you need to use a trick for this and subsequent calculations (in fact, it would make sense to use this trick for previous calculations as well, even though you do not need to). As an example, I will take the final number which you would need to multiply by 4 lots of 256 (i.e. 20*256*256*256*256)...
a) take the number and multiply by 256 (which will give 5120) - break this into the powers of 10 like you have done before, this time into an INT array (say temp[14]).
b) multiply each of these digits by 256 each, giving ...,1280,256,512,0
c) then perform the decimal carries similar to step (3) above. For example: when working on the 512 entry, the "5" gets added to the 1280, the "1" to 256, and "2" stays in the same position. So, you would eventually end up with ...,1,3,1,0,7,2,0.
d) you then need to repeat steps (b) and (c) another 2 times. At this point, you will end up with the result of 20*256*256*256*256, i.e. ...8,5,8,9,9,3,4,5,9,2,0
e) finally, add each of these to the existing values in your "id" variable.
I know the procedure is not complete, but I hope you can see the methodology.
First the shortcut - you do not need to convert to hex. If you receive "20 0 222 21 209", then this equals 209 + (21*256) + (222*256*256) + (0*256*256*256) + (20*256*256*256*256) = 85913900497.
Second, a potential solution. Create a byte array of 14 bytes (I'll call this id[14]), then follow this procedure:
1) take the low byte (209) and break it into it's powers of 10 (i.e. 2, 0, and 9) and add these to the id locations id[11], id[12] and id[13]. At this stage, the id variable would contain: 0,0,0,0,0,2,0,9
2) take the next byte (21) and multiply it by 256 (to give 5376). Your holding variable will need to be an integer rather than a byte for this. Add these to the relevant id digits, which would result in "id" as follows: 0,0,0,0,0,0,0,0,0,0,5,5,7,15.
3) now cycle through from id[13] to id[0] and if the number is above 9, take 10 away and add 1 to the next number. This would leave "id" as 0,0,0,0,0,0,0,0,0,0,5,5,8,5.
4) unfortunately, the precision of numbers available within this version of Flowcode now runs out. So you need to use a trick for this and subsequent calculations (in fact, it would make sense to use this trick for previous calculations as well, even though you do not need to). As an example, I will take the final number which you would need to multiply by 4 lots of 256 (i.e. 20*256*256*256*256)...
a) take the number and multiply by 256 (which will give 5120) - break this into the powers of 10 like you have done before, this time into an INT array (say temp[14]).
b) multiply each of these digits by 256 each, giving ...,1280,256,512,0
c) then perform the decimal carries similar to step (3) above. For example: when working on the 512 entry, the "5" gets added to the 1280, the "1" to 256, and "2" stays in the same position. So, you would eventually end up with ...,1,3,1,0,7,2,0.
d) you then need to repeat steps (b) and (c) another 2 times. At this point, you will end up with the result of 20*256*256*256*256, i.e. ...8,5,8,9,9,3,4,5,9,2,0
e) finally, add each of these to the existing values in your "id" variable.
I know the procedure is not complete, but I hope you can see the methodology.
Re: Hex to Decimal
Steve,
How would i go about intergrating the shortcut calculation in to my Flowcode program, program is post on above reply
Rgds
Wayne
How would i go about intergrating the shortcut calculation in to my Flowcode program, program is post on above reply
Rgds
Wayne
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Hex to Decimal
Sorry, Wayne.
I've got loads of work on here at the moment. If I get any free time at home, I'll see if I can knock together some example macros that will make this procedure easy - but I can't promise anything.
I've got loads of work on here at the moment. If I get any free time at home, I'll see if I can knock together some example macros that will make this procedure easy - but I can't promise anything.
Re: Hex to Decimal
Thanks steve,
Every time i do the shortcut sum i get 85930677713 ?
What am i doing wrong
Rgd
Wayne
Every time i do the shortcut sum i get 85930677713 ?
What am i doing wrong
Rgd
Wayne
Re: Hex to Decimal
Hi,
can anyone in this forum help me with this calculation as i,m stuck
tag4 + (tag3*256) + (tag2*256*256) + (tag1*256*256*256) + (tag*256*256*256*256) = 85913900497.
Tag to tag4 are variable data
example
tag = 20
tag1 = 0
tag2 = 222
tag3 = 21
tag4 = 209
Thanks
can anyone in this forum help me with this calculation as i,m stuck
tag4 + (tag3*256) + (tag2*256*256) + (tag1*256*256*256) + (tag*256*256*256*256) = 85913900497.
Tag to tag4 are variable data
example
tag = 20
tag1 = 0
tag2 = 222
tag3 = 21
tag4 = 209
Thanks
Re: Hex to Decimal
Please can someone give me hand with the above, so i can put my E-blocks to some use
Pleading
Proton
Pleading
Proton
Re: Hex to Decimal
Is there any information on this site on how to creat a macro, so i can have a go at doing this calculation.
thanks
wayne
thanks
wayne
- 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: Hex to Decimal
Hello Wayne
In Flowcode click on Help and Contents, Then scroll down to the section entitled working with macros and variables and look at the relevant help topics. Hopefully this should get you up to speed with using macros.
In Flowcode click on Help and Contents, Then scroll down to the section entitled working with macros and variables and look at the relevant help topics. Hopefully this should get you up to speed with using macros.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Hex to Decimal
Benj,
The answer to my calculation is larger than 1 byte, so what type of varible do i use. INT is ok for the first calculation, but when i get to tag2*256*256 it comes back as zero
Rgds
Wayne
The answer to my calculation is larger than 1 byte, so what type of varible do i use. INT is ok for the first calculation, but when i get to tag2*256*256 it comes back as zero
Rgds
Wayne
Re: Hex to Decimal
Hi steve,
Sorry for pestering you, But how do i break down the 209 (tag) into powers of ten. I will get my head round this !
Rgds
Wayne
Sorry for pestering you, But how do i break down the 209 (tag) into powers of ten. I will get my head round this !
Rgds
Wayne
- 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: Hex to Decimal
Hello
To break a variable into powers of ten you will have to do something similar to the following.
INT_Var = 10500
thousands = INT_Var MOD 1000 //should equal 10
INT_Var = INT_Var - (thousands * 1000)
hundreds = INT_Var MOD 100 //Should equal 5
INT_Var = INT_Var - (hundreds * 100)
tens = INT_Var MOD 10 //Should equal 0
INT_Var = INT_Var - (tens * 10)
units = INT_Var //Should equal 0
To break a variable into powers of ten you will have to do something similar to the following.
INT_Var = 10500
thousands = INT_Var MOD 1000 //should equal 10
INT_Var = INT_Var - (thousands * 1000)
hundreds = INT_Var MOD 100 //Should equal 5
INT_Var = INT_Var - (hundreds * 100)
tens = INT_Var MOD 10 //Should equal 0
INT_Var = INT_Var - (tens * 10)
units = INT_Var //Should equal 0
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel