Solved

My Cardinal is signed !

Posted on 2000-04-11
6
238 Views
Last Modified: 2011-04-14
According to the Delphi 3 Help file, cardinals are meant to be a 32 bit unsigned number.

However it is definately a 32 bit signed number on my system. (WinNT)

Try typing '(cardinal($7FFFFFFF)+1)' in the 'evaluate/modify' window and you will get a range check error instead of the correct answer of $80000000.

Also Cardinal($FFFFFFFF) gives '-1'.

Q1. Is this unique to me or does everyone else have the same issue?

Q2. So how do I get a 32 bit unsigned number?  (Simply printing it out differently at the end doesn't help, because the maths in the middle should be correct to)

(For example: $8000 0000 / 2 = ??
  Signed:   $C000 0000
  Unsigned: $4000 0000)

0
Comment
Question by:mac_rowe
[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
  • 2
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 2706011
I have noticed that various debug windows sometimes 'lie' about the real value of a variable, and at other times can do strange things as you describe.

However, cardinal is NOT a 32 bit unsigned int in D3 - it is a 31 bit unsigned int!

In D5 (D4 too, I think, but not sure) cardinal is a 32 bit unsigned int.

D5 also has LongWord which is 32 bit unsigned, but I am not sure if D3 has this.

You could do the maths in a float variable and round() the result, or it you are just doing things like DIV by 2, then you can use SHR to do it...

Cheers,

Raymond.


0
 
LVL 20

Expert Comment

by:Madshi
ID: 2706680
Ray is right. D3 has no 32bit unsigned support at all. Perhaps you can use the type "comp". Not very handy though.
In D4 Borland introduced "real" 32bit unsigned support with cardinal = longWord = 32bit unsigned.

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2706684
P.S: You should seriously think about upgrading to D4 or D5, because there are tons of other quite important language extensions like int64 (real 64bit integer type), predefined parameters, function/method overloading and more...
0
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!

 

Author Comment

by:mac_rowe
ID: 2710380
Hmm, so the Delphi documentation is a lie.  Didn't someone notice this before they released it ?

Ironically I use D5 at home but here at work we are on good ol' fashioned D3.  When you have several licenses it is quite expensive to upgrade, so I'd like to stick to D3 for the moment, rather than force the entire company to upgrade.

I've found so far the best solution is to turn range checking off and simply pretend that it is unsigned.  It is pretty good apart from the division problem mentioned earlier.

I'll check out a couple of possibilities...

0
 

Author Comment

by:mac_rowe
ID: 2721738
Yes, you get a 'excellent' grade for proving to me that I wasn't mad after all.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2724498
Your welcome!

Cheers,

Raymond.
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

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 60
tidtcpserver connection lost handle 2 109
PHP preg_replace code convert to Delphi 14 79
Twebbrowser in Fire monkey android scrolling to bottom 1 67
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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