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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:02:58+00:00 2026-06-16T10:02:58+00:00

In the following Java program I cannot understand what this line does: wert =

  • 0

In the following Java program I cannot understand what this line does:

wert = (wert * mult + inkr) & 0x7FFFFFFFL;

I understand what the bitwise operators do in conditions, but there are principally two numbers (the hexadecimal is the maximum value of Integers in Java). I do not understand, why the & 0x7FFFFFFFL; has even some influence in this line. In my opinion, the variable wert should simply have the value of (wert * mult + inkr) because it’s true.
Though I figured out that the & 0x7FFFFFFFL; obviously does have some influence only if (wert * mult + inkr) is negative. Why and what exactly happens in this line?

Annotation: This should be a program for simulating a lottery drawing. I am aware of the error in the program, right where the comment is. But this is not relevant for me right now.
Still it would be great if someone could me tell following not really Java-specific question: what sense got the variables mult and inkr?

public static void main(String args[]) {
    int kugeln = 49;
    int ziehen = 6;
    int mult = 1103515245;
    int inkr = 12345;
    long wert = System.currentTimeMillis();
    int zahlen[] = new int[kugeln];

    for(int i = 0; i < kugeln; i++) {
        zahlen[i] = i + 1;
        wert = (wert * mult + inkr) & 0x7FFFFFFFL;
    }

    for(int i = 0; i < ziehen; i++) {
        int index = (int)(wert / 10) % (49 - i);
        int temp = zahlen[49 - i]; // Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 49
        zahlen[49 - i] = zahlen[index];
        zahlen[index] = temp;
        wert = (wert * mult + inkr) & 0x7FFFFFFFL;
    }

    int superzahl = (int)(wert / 10) % 10;
    for(int i = 0; i < ziehen; i++) {
        System.out.println(zahlen[49 - i]);
    }

    System.out.println(superzahl);
}
  • 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-16T10:02:59+00:00Added an answer on June 16, 2026 at 10:02 am

    Using bitwise AND with non-booleans will bitwise AND together all of the bits of the two numbers one by one.

    In this case, the number 0x7FFFFFFFL is the hexadecimal representation of a number that is a 0 bit followed by 31 1 bits:

    01111111111111111111111111111111
    

    By ANDing this with an integer, you preserve the lower 31 bits (since 1 & x = x for any x) and clear the highest bit (since 0 & x = 0 for any x). Since Java uses a 32-bit signed two’s-complement representation, this has the effect of clearing the sign bit, forcing the number to be positive.

    My guess is that this program is using some sort of rolling hash function where the resulting number has to be positive. To do this, the code constantly updates the integer by combining it with more and more information, and at each step forces the number to be positive by clearing the sign bit.

    Hope this helps!

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

Sidebar

Related Questions

I get the following error when running mongo-hadoop streaming: java.io.IOException: Cannot run program "mapper.py":
Why this line doesn't work? import static java.nio.file.AccessMode.*; Eclipse says: The import java.nio.file cannot
i using the following line in my java program LegendItem item1 = new LegendItem(US,
While building with ant, I am getting the following error: java.io.IOException: Cannot run program
The requirements of the following java assignment are unclear to me. Does anyone understand
I'm calling a java program from my python code in the following way: subprocess.check_output([java,
I get the following error when I run a java program: Exception in thread
Given the following program: import java.io.*; import java.util.*; public class GCTest { public static
Why gives the following Windows 7 .cmd command script: set SUN_JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_17 if
Observe the following program written in Java (complete runnable version follows, but the important

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.