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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:18:02+00:00 2026-05-11T09:18:02+00:00

I have a tree control with checkboxes next to each node that allows for

  • 0

I have a tree control with checkboxes next to each node that allows for checked, unchecked and middle checked states on the nodes. When clicking a node, the parent and children are updated. The code I found that does the trick uses bit shifting and I’m trying to understand what exactly is happening.

Can someone explain the following code? Or even better, rewrite this code so it is easier to understand?

// click event handler private function eventMessageTree_itemCheckHandler(event:TreeEvent):void {   var node:ITreeNode = ITreeNode(event.item);   var checkState:uint = TreecheckboxItemRenderer(event.itemRenderer).checkBox.checkState;   updateParents(node, checkState);   updateChilds(node, checkState); }  private function updateChilds(item:ITreeNode, value:uint):void {   var middle:Boolean = (value & 2 << 1) == (2 << 1);   var selected:Boolean = (value & 1 << 1) == (1 << 1);    if (item.children.length > 0 && !middle) {     for each (var childNode:ITreeNode in item.children)     {       childNode.checked = value == (1 << 1 | 2 << 1) ? '2' : value == (1 << 1) ? '1' : '0';       updateChilds(childNode, value);     }   } }  private function updateParents(item:ITreeNode, value:uint): void {   var checkValue:String = (value == (1 << 1 | 2 << 1) ? '2' : value == (1 << 1) ? '1' : '0');   var parentNode:ITreeNode = item.parent;   if (parentNode) {     for each (var childNode:ITreeNode in parentNode.children) {       if (childNode.checked != checkValue) {         checkValue = '2';       }     }     parentNode.checked = checkValue;     updateParents(parentNode, value);   }     } 
  • 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-11T09:18:03+00:00Added an answer on May 11, 2026 at 9:18 am

    Basically, an expression like this:

    var middle:Boolean = (value & 2 << 1) == (2 << 1); 

    Is counter-intuitive. You usually test bits by shifting the constant 1 to the left, since that lets the number of bits shifted be the same as the index of the bit, counting the LSB (rightmost) bit as bit number 0.

    Also, there’s no point in testing the result with a == comparison, since it’s always going to be either 0 or non-zero, so you can at least test for something simpler if your language requires that.

    In C and C++, which by default interpret a non-zero integer as ‘true’, the comparison is totally unnecessary and just serves to introduce clutter, repetition, and increase the risk of bugs.

    I’d write this like so:

    var middle:Boolean = (value & (1 << 2)) != 0; 

    The extra parenthesis should help make it clearer how things are grouped. Note how ‘2 << 1’ was rewritten as ‘1 << 2’. This is not just a ‘switch’, you need to compute the proper shift to get the same bit value, 4 in this case.

    Of course you could put the bit-testing into subroutines and call them, to make the code more readable.

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

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 115k
  • 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 There is no straigthforwad solution for sharing session variables between… May 11, 2026 at 10:28 pm
  • Editorial Team
    Editorial Team added an answer You don't need to join a thread, but it is… May 11, 2026 at 10:28 pm
  • Editorial Team
    Editorial Team added an answer To answer my own question: it looks like I forgot… May 11, 2026 at 10:28 pm

Related Questions

Ok, I have a set of checkboxes for selecting criteria. For argument's sake, we'll
I'm going to advise a company on a project soon, and I'm not too
Let's say that the company has a large number of separate small to medium
I am using a Tree control with an XMLListContainer dataProvider.... I use an itemOpen

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.