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 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
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: Rails 3.0.1 Ruby 1.8.7 MySQL 5.5.16 Community server...Jdk 1.6 gem 'sunspot_rails' gem 'sunspot_solr'
Environment: Windows Server 2008 R2 on Amazon EC2 Netbeans IDE with Glassfish started on
Environment I am using the native document management integration between Microsoft Dynamics CRM 2011
Environment info: *Windows Vista *PHP 5.2.9-2 I'm working on a project. Let's say it's
ENVIRONMENT: C# I have a table of equivalent values, like this: CHEVR = CHEVROLET
environment/cucumber.rb: ... # gem dependencies config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.0' unless
Environment: Seam, Richfaces The following code snippet causes the method getUsers to be called

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.