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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:39:35+00:00 2026-05-26T06:39:35+00:00

I have a speed question for Java. I am making a chess program, and

  • 0

I have a speed question for Java. I am making a chess program, and I want to check if is a good idea to use one int as a variable to store four int variables, in which the values range from 1 to 4 bits.

The problem is that I’ll often have to extract and put in new parts of the variable, so that will cost quite some bitwise operations.

Code:

int fromX = 4, fromY = 5, toX = 6, toY = 7;
int move = 0
move |= toY;
move = move << 4;
move |= toX;
move = move << 4;
move |= fromY;
move = move << 4;
move |= fromX;

doWork(move);

or

int fromX = 4, fromY = 5, toX = 6, toY = 7;
doWork(fromX, fromY, toX, toY);

doWork() will do a lot of different things with the coordinates, mostly extract them from the ‘int’, or just use the variables.

Which should I use?

  • 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-26T06:39:35+00:00Added an answer on May 26, 2026 at 6:39 am

    I want to check if is a good idea to use one ‘unsigned int’ as a variable to store four ‘int’ variables

    No, this is a Bad Idea™ for a bunch of reasons.

    1. This would be highly inefficient

    2. Very hard to read

    3. (consequently) very hard to debug

    Sure, it may save a few bytes here and there, but honestly, I buy my RAM-modules in gigabytes these days.

    My suggestion:

    Write up your entire chess-program. If you run into performance problems, profile the program to see where the bottle-necks are, and do something about those. (I can guarantee you that you won’t start packing several numbers into an int once you reach this point.)

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

Sidebar

Related Questions

Quick question here: why not ALWAYS use ArrayLists in Java? They apparently have equal
I have a speed critical multithreaded program which involves data in a tree structure.
I am programming in C++ or Java. So I want to use Vim editor,
I have a performance question in java. I have a large indexed table in
I want to ask a complex question. I have to code a heuristic for
I have seen the question: Communication between two separate Java desktop applications (answer: JGroups)
I have a Full Speed device that specifies the max packet size as 256
I have read that LinkedHashMap has faster iteration speed than HashMap because its elements
Does anyone have any tips that could help speed up a process of breaking
We have a linux app that depends on the speed with which the user

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.