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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:51:40+00:00 2026-06-03T03:51:40+00:00

In my 2D environment a player can move diagonally, horizontally and vertically. When looking

  • 0

In my 2D environment a player can move diagonally, horizontally and vertically. When looking at the grid below you can see that the player (marked as x) can move to 8 different spots from where he (or she xD) is now.

 1 | 2 | 3
-----------
 4 | x | 5
-----------
 6 | 7 | 8

Instead of storing this as (which is a lot of data):

Go1 = true;
Go2 = true;
Go3 = true;
Go4 = true;
Go5 = true;
Go6 = true;
Go7 = true;
Go8 = true;

I think it’s better to first convert it to:

11111111 

..which represents 8 times true. With that in mind and the knowledge that the decimal representation of the binary number 11111111 (8 bit) equals the nummer: 255 I rather convert it and store the current-possible-places-to-move-to as 255.

Code:

x = parseInt(11111111);
var bin = x.toInt(2);
document.write(bin);​

That means that if there’s a wall at (for example) location (1, 4 and 6) = left side from player, the player can only move to:

01101011

Which can be stored as: 107.

Let’s say that the player wants to move to location 3. This means that my script has to do the following:

  1. convert the 3 digit current-possible-places-to-move-to number back to binary
  2. get the 3rd number from that binary code
  3. check if that number is a 1 or 0

Question:
Is it possible to calculate this without converting to binary back and forth in Javascript? If yes, how?

  • 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-03T03:51:40+00:00Added an answer on June 3, 2026 at 3:51 am

    Bit-shift so that the relevant digit is the least significant, and then test the parity of the value:

    function getPositionInRow(rowval, pos) {
        return (rowval >> (8 - pos)) % 2;
    }
    

    This will return value at the specified position, counting from the left starting the index at 1.

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

Sidebar

Related Questions

I'm writing a console-environment Hangman game for my introductory programming class. The player chooses
Environment I'm working on a C++ application that uses SQL Native Client 9.0 to
I'm writing a game that is played in a pseudo-Internet like environment. I'm just
Given a quaternion camera, how can I calculate its rotation when the player can
Environment: Windows Server 2003 R2 Enterprise 64bit, SP2 .NET framework is supposedly installed (2.0
Environment: Windows 2003 Server (32 bit); IIS6, ASP.NET 2.0 (3.5); 4Gb Ram; 1 Worker
Environment: Rails 2.2.2, Oracle 10g Most of the columns declared date in my ActiveRecord
Environment: Team Foundation Server 2005 Visual Studio 2008 I have a reasonably large project
Environment is VS2008, .Net 3.5 The following C# code (note the specified encoding of
Environment: C# projects, Visual studio 2008, C#, .Net 3.5, MSBuild Objective: Run my own

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.