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 8398677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:06:37+00:00 2026-06-09T21:06:37+00:00

How do I use % properly not to get negative result? <?php $x =

  • 0

How do I use % properly not to get negative result?

<?php 
    $x = 1103515246*12345;
    echo $x." ".decbin($x)."</BR>";
    $y = $x % (1 << 15);
    echo $y." ".decbin($y)."</BR>";
?>

Output:

13622895711870      11010011110111000001011001111110

-27010              11111111111111111001011001111110

RESOLVED

$y = bcmod($x,(1 << 15)); Solves the issue. Thank you for quick help! It was my first question!

  • 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-06-09T21:06:39+00:00Added an answer on June 9, 2026 at 9:06 pm

    problem is that $x not integer but float and casted to negative int when you use %

    Try use BCMath instead for big numbers

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

Sidebar

Related Questions

The third part export application we use will not properly render paragraph tags (does
I'm trying to use JQuery Slidetoggle functionality, but not able to use properly. The
I'm trying to use JQuery toggle functionality, but not able to use properly. Instead
well i do not know how to use sql union properly . i have
I would like how to use the not in XPath properly. I just can't
I do not know how to properly use divisor ip core from xilinx and
Can someone show me to use xargs properly? Or if not xargs, what unix
I don't get how to use structs properly to achieve my goal of calculating
I am trying to use vim properly - to aid me I've mapped my
I am trying to properly use Ninject to inject log4net logging into my MVC3

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.