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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:55:12+00:00 2026-06-17T20:55:12+00:00

I am a student in high school and I am currently learning in Delphi

  • 0

I am a student in high school and I am currently learning in Delphi XE3. We are learning about BIT manipulation. We have an assignment and while I have read a lot on the subject and understand the entire process of storing information in Bits and SHL/SHR I am having difficulty understanding how to do this process in Delphi.

The assignment is as follows:

Decimal        Hexidecimal    Binary
1              0x0001         0000000000000001
2              0x0002         0000000000000010
4              0x0004         0000000000000100

Passing an integer value in an XML file to identify the options set. For example. If I wanted to send option 1 and option 2, I would add 1+2=3. I would send 3 as the number to specify that options 1 and 2 are true.

On the client the binary value would be 0000000000000011 = 3

From what I have read I need to use a mask but I do not understand how to do this. How would do I use masks in Delphi ot obtain the individual values which would be True or False.

I tried doing this in a regular Integer variable but it always gets treated as an Integer and the result is very strange. If I convert the integer to a binary string representation and I iterate thru the characters the result is correct but I am assuming that I should not be doing this with strings. Any help or an example would be greatly appreciated. Thank you.

  • 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-17T20:55:14+00:00Added an answer on June 17, 2026 at 8:55 pm

    You usually check if a particular bit is set in a Integer variable using the and binary operator, and you set individual bits using the or operator, like this:

    const
      OPTION_X = $01;
      OPTION_Y = $02;
      OPTION_Z = $04;
    
    var
      Options: Byte;
    begin
      Options := OPTION_X or OPTION_Y;  //actually 3, like in your example
      //check if option_X is set
      if (Options and OPTION_X) = OPTION_X then
        ShowMessage('Option X is set');  //this message is shown, because the bit is set
      //check if option_Z is set
      if (Options and OPTION_Z) = OPTION_Z then
        ShowMessage('Option Z is set');  //this message is NOT shown
    end;
    

    The different OPTION_ constants, are actually masks, in the sense they are used to mask bits to zero (to check if a particular bit is set) or to mask bits to 1 (to set a particular bit).

    Consider this fragment:

    begin
      ..
    
      if cbOptionX.Checked then
        Options := Options or OPTION_X;
      ..
    

    the or will mask the first bit to 1. If we start with a Options value (in binary) of 01010000, the resulting Options would be 01010001

        01010000   
     OR 00000001  //OPTION_X 
      = 01010001   
    

    the same value is used to mask all the other bits to 0 to check if a particular bit is set. The if condition, for example: (Options and OPTION_Z) = OPTION_Z, does this:

    • first it MASKS all the non-interesting bytes of the Option variable to 0. If we consider the last value of 01010001, the operation will result in clearing all the bits, but the first.

          01010001   
      AND 00000001   
        = 00000001   
      

    considering a starting value of 01010000 it will return zero:

            01010000   
        AND 00000001   
          = 00000000   
    
    • next, it compares if that value is equal to the mask itself. If it is equal, the bit was set in the original Options variable, otherwise it was not set. If your mask contains only one bit, that’s matter of taste, you can just check if the resulting value is, for example, different than 0, but if your mask contains multiple bits and you want to check if all the bits was set, you have to check for equality.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently tutoring a high school student in AP Java and she asked me
My student(high school) asked me a question about regex matching a word which contains
I am a newbie Computer Science high school student and I have trouble with
I'm a beginner high school java student and I have to make a simple
I'm a high school student, and I have a decent amount of programming experience
I'm a final year high school student and want to help my father secure
I am a high school student and am thinking of making a robot that
So I'm a high school student taking an iPhone development class. For my final
I'm working on a simple text messaging service for my high school's student council
I'm currently developing an attendance system for my high school. Right now, my method

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.