Page 1 of 1

ULong Variable not working!

Posted: Sat Jan 11, 2020 10:12 pm
by sysprofessional
Hi everyone,

I'm using FC 6.1.4 with 16f887, facing issue with Ultra Long variable ,it should handle value between (0 to 4294967295) .
But its acting like Long variable ,(-2147483648 to 2147483647), Can someone please resolve this for me ?
any help will be appreciated,

Thanks in advance

Re: ULong Variable not working!

Posted: Sat Jan 11, 2020 10:36 pm
by kersing
Could you provide some context? May-be even a flowchart demonstrating the issue?

Re: ULong Variable not working!

Posted: Sat Jan 11, 2020 11:03 pm
by sysprofessional
kersing wrote:Could you provide some context? May-be even a flowchart demonstrating the issue?
Hi Kersing,
Simple test Just put a calculation icon in flowchart and calculate the value " test = 2+2147483647 " result overflowing like -2147483647,test variable already added as ULong.
Flowchart image attached.
Untitled-1.jpg
Untitled-1.jpg (97.15 KiB) Viewed 8259 times

Re: ULong Variable not working!

Posted: Sun Jan 12, 2020 12:02 am
by mnf
It could well be that the display routine in FC expects a signed long rather than an unsigned long. The value is probably correct - but is displayed incorrectly...

Martin

Re: ULong Variable not working!

Posted: Sun Jan 12, 2020 12:05 am
by sysprofessional
ok i try to simulate.

Re: ULong Variable not working!

Posted: Sun Jan 12, 2020 12:45 am
by sysprofessional
Unfortunately same result in simulation,i'm wondering because i have write many programs using ULong,may be one year ago,but this time idk why strange behavior from ULong.I have recently uninstalled FC 6.1.4 and install old version 6.1.0,but no luck ,can it be windows issue?
here is the simulation result ULong incremented by 1 , every second
ULongTest.jpg
ULongTest.jpg (217.79 KiB) Viewed 8250 times

Re: ULong Variable not working!

Posted: Sun Jan 12, 2020 2:56 am
by mnf
Same result - as soon as bit 31 is set - the display routine assumes that it is a negative number. Try converting the number to a hex string then output that....

Martin

Re: ULong Variable not working!

Posted: Sun Jan 12, 2020 4:32 pm
by sysprofessional
I have tested its working fine on hardware, just FC simulating it wrongly,
tested in this way.
1. receiving 32bit string at Comport ,
2. converted it to ULong.
3. splitting into 4 bytes ,
4. stored into EEprom.
5. extract back to 4 bytes, byte0,byte1,.....and so on
i have checked here all 4 values in the EEprom perfect.
6. combining these 4 values to a ULong.

its working fine till here but when i try to convert it to string at step 7 ,again resulting in Long (-2147483648 to 2147483647)

7. String = ToString$(ULong);

any suggestions .....?
how can i convert 32bit Ultra Long to String.

Re: ULong Variable not working!

Posted: Sun Jan 12, 2020 5:01 pm
by mnf
You can use NumberToHex$(x) - which returns a string. This works correctly (ie it takes an unsigned long and returns a string)

If you need the value in decimal that is also fairly easy - attached is a very simple demo - that first converts (-1 - so maximum 32 bit number (2^32 - 1)) to a hex number and then converts it to a decimal string....
test.fcfx
(7.72 KiB) Downloaded 275 times
Martin

Re: ULong Variable not working!

Posted: Tue Jan 14, 2020 12:44 pm
by sysprofessional
I have already done using that method. btw thanks for your co-operation .

Best of luck all of you guys.

Re: ULong Variable not working!

Posted: Thu Jan 16, 2020 11:09 am
by Steve
For info, I checked v8 and it seems to work fine. I assume this bug was fixed a while ago in v7 or v8.
ulong.png
(18.4 KiB) Downloaded 1222 times