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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:06:55+00:00 2026-05-10T21:06:55+00:00

I’m someone who writes code just for fun and haven’t really delved into it

  • 0

I’m someone who writes code just for fun and haven’t really delved into it in either an academic or professional setting, so stuff like these bitwise operators really escapes me.

I was reading an article about JavaScript, which apparently supports bitwise operations. I keep seeing this operation mentioned in places, and I’ve tried reading about to figure out what exactly it is, but I just don’t seem to get it at all. So what are they? Clear examples would be great! 😀

Just a few more questions – what are some practical applications of bitwise operations? When might you use them?

  • 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. 2026-05-10T21:06:55+00:00Added an answer on May 10, 2026 at 9:06 pm

    Since nobody has broached the subject of why these are useful:

    I use bitwise operations a lot when working with flags. For example, if you want to pass a series of flags to an operation (say, File.Open(), with Read mode and Write mode both enabled), you could pass them as a single value. This is accomplished by assigning each possible flag it’s own bit in a bitset (byte, short, int, or long). For example:

     Read: 00000001 Write: 00000010 

    So if you want to pass read AND write, you would pass (READ | WRITE) which then combines the two into

    00000011 

    Which then can be decrypted on the other end like:

    if ((flag & Read) != 0) { //... 

    which checks

    00000011 & 00000001 

    which returns

    00000001 

    which is not 0, so the flag does specify READ.

    You can use XOR to toggle various bits. I’ve used this when using a flag to specify directional inputs (Up, Down, Left, Right). For example, if a sprite is moving horizontally, and I want it to turn around:

         Up: 00000001    Down: 00000010    Left: 00000100   Right: 00001000 Current: 00000100 

    I simply XOR the current value with (LEFT | RIGHT) which will turn LEFT off and RIGHT on, in this case.

    Bit Shifting is useful in several cases.

    x << y 

    is the same as

    x * 2y

    if you need to quickly multiply by a power of two, but watch out for shifting a 1-bit into the top bit – this makes the number negative unless it’s unsigned. It’s also useful when dealing with different sizes of data. For example, reading an integer from four bytes:

    int val = (A << 24) | (B << 16) | (C << 8) | D; 

    Assuming that A is the most-significant byte and D the least. It would end up as:

    A = 01000000 B = 00000101 C = 00101011 D = 11100011 val = 01000000 00000101 00101011 11100011 

    Colors are often stored this way (with the most significant byte either ignored or used as Alpha):

    A = 255 = 11111111 R = 21 = 00010101 G = 255 = 11111111 B = 0 = 00000000 Color = 11111111 00010101 11111111 00000000 

    To find the values again, just shift the bits to the right until it’s at the bottom, then mask off the remaining higher-order bits:

    Int Alpha = Color >> 24 Int Red = Color >> 16 & 0xFF Int Green = Color >> 8 & 0xFF Int Blue = Color & 0xFF 

    0xFF is the same as 11111111. So essentially, for Red, you would be doing this:

    Color >> 16 = (filled in 00000000 00000000)11111111 00010101  (removed 11111111 00000000) 00000000 00000000 11111111 00010101 & 00000000 00000000 00000000 11111111 = 00000000 00000000 00000000 00010101 (The original value) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm a C# programmer, so I'm sorry if this suggestion… May 12, 2026 at 1:18 am
  • Editorial Team
    Editorial Team added an answer Preferences -> General -> Editors -> Text Editors -> Annotations… May 12, 2026 at 1:18 am
  • Editorial Team
    Editorial Team added an answer It is a generally accepted best practice to always scope… May 12, 2026 at 1:18 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.