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

  • SEARCH
  • Home
  • 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 6822069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:37:11+00:00 2026-05-26T21:37:11+00:00

I am using PHP 5.3. On my 32-bit system the size of an INT:

  • 0

I am using PHP 5.3.

On my 32-bit system the size of an INT:

print "PHP_INT_MAX: " . PHP_INT_MAX . "\n";
print "PHP_INT_SIZE: " . PHP_INT_SIZE . " bytes (" . (PHP_INT_SIZE * 8) . " bits)\n";
  • PHP_INT_MAX: 2147483647
  • PHP_INT_SIZE: 4 bytes (32 bits)

However, part of an an encoding algorithm I am using relies on the fact that an int is the above size (4 bytes). When I run the code on my web host’s server, it is a 64-bit system and the int size is twice as large.

Is there a way to force “(int)” cast to use the 32-bit size?

For example, assume the following code:

$test = 4170266799;
print $test;                     
print (int) $test;

On my 32-bit system, the output is:

4170266799
-124700497

On my 64-bit system, the output is:

4170266799
4170266799

Is it possible to force the value of an INT to be 4 bytes, even when the architecture changes from 32-bit to 64-bit?

  • 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-26T21:37:12+00:00Added an answer on May 26, 2026 at 9:37 pm

    Referencing this question on Stack Overflow, I have found a solution that seems to work in my early tests:

    function thirtyTwoBitIntval($value)
    {                  
        if ($value < -2147483648)
        {
        return -(-($value) & 0xFFFFFFFF);
        }
        elseif ($value > 2147483647)
        {
            return ($value & 0xFFFFFFFF);
        }
        return $value;
    }
    
    
    $test = 4170266799;
    print $test;                     
    print (int) $test;
    print thirtyTwoBitIntval($test);
    

    And the output on the 32-bit system is:

    4170266799  # $test = 4170266799
    -124700497  # (int) $test
    -124700497  # thirtyTwoBitIntval($test);
    

    And the output on the 64-bit system is:

    4170266799  # $test = 4170266799
    4170266799  # (int) $test
    -124700497  # thirtyTwoBitIntval($test);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do a little bit of math using dates in PHP.
I am looking to create a Web Chat system using PHP, MySQL and JavaScript.
I'm trying to build a little bit advanced users system using Joomla, but I
I'm using Amazon Web Services' PHP SDK for their Flexible Payments System. Somewhere in
I am currently writing a system for publishing tutorials about basic PHP. However, I
I'm using PHP to make a simple caching system, but I'm going to be
I have a Private messaging system using PHP and mySQL with notification. The database
Using PHP, I can convert MySQL data or static table data to csv, Excel,
Using PHP, I am trying to delete a record, but I want to check
using php and mysql I have two tables, a users table and a profiles

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.