Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:43:45+00:00 2026-05-26T20:43:45+00:00

Declaration… const n = 2 shl 33 will set constant n to value 4

  • 0

Declaration…

const
  n = 2 shl 33

will set constant n to value 4 without any compiler complaint!

Also…

Caption := IntToStr(2 shl 33);

…return 4 instead 8589934592.
It looks like the compiler calculates like this:

2 shl 33 = 2 shl (33 and $1F) = 4

But without any warning or overflow.

The problem remains if we declare:

const
  n: int64 = 2 shl 33;

The number in constant is still 4 instead 8589934592.

Any reasonable work around?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:43:45+00:00Added an answer on May 26, 2026 at 8:43 pm

    You’re looking for the wrong results, according to both the Delphi compiler and Windows 7’s calculator in programmer mode. (The answer you’re wanting is actually 2 shl 32, BTW.)

    You need to cast both sides of the shl to Int64:

    const
      n = Int64(2) shl Int64(33);
    

    This produces

    N = 17179869184;
    

    The current documentation (for XE2, but applies to earlier versions of Delphi as well) notes this in Fundamental Integer Types. However, that page mentions only having to cast one of the operands as Int64; my test shows it to require both operands be typecast in the const declaration above – typecasting only one (regardless of which one) also resulted in `n = 4;’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can the following declaration be expressed with const first (without typedef)? double* const
This declaration causes an overflow in VBA: Const OVERFLOWS As Long = 10 *
Given a declaration like this: class A { public: void Foo() const; }; What
Given the following declaration: double x; What is the value of x ? Is
If I write this declaration: unsigned ux = 2147483648; (2 31 ), will the
In the declaration of my form,I made a messagehandler: procedure MessageHandler(var Msg:TMessage);Message MSG_ACCESS; const
I have this method declaration in Util.h file 30:string to_string(const bit_vector& v); Util.cc file
Declaration inside the class: Integer operator+ (const Integer& right); Definition outside the class: Integer
I have a class declaration(.h file) like so: struct MyClass { static const uint32_t
I have the following declaration. namespace test{ static cl_option* find_opt(const int &val, const cl_option

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.