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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:36:21+00:00 2026-06-07T07:36:21+00:00

I’m reading a bunch of bytes from a binary file. It is a RAR

  • 0

I’m reading a bunch of bytes from a binary file. It is a RAR file. I’m interested in the 11th and 12th bytes of the file because the header specifications state:

HEAD_FLAGS Bit flags: 2 bytes

            0x0001  - Volume attribute (archive volume)
            0x0002  - Archive comment present
                      RAR 3.x uses the separate comment block
                      and does not set this flag.

            0x0004  - Archive lock attribute
            0x0008  - Solid attribute (solid archive)
            0x0010  - New volume naming scheme ('volname.partN.rar')
            0x0020  - Authenticity information present
                      RAR 3.x does not set this flag.

            0x0040  - Recovery record present
            0x0080  - Block headers are encrypted
            0x0100  - First volume (set only by RAR 3.0 and later)

            other bits in HEAD_FLAGS are reserved for
            internal use

The file that I’m playing with has 00 and 0D as positions 11 and 12 respectively.

I can’t make sense of these two values as they are bit flags (which I have failed to understand).

I have these two values in byte array that is 12 bytes long. What I need to check in this sequence is whether the flag 0x0100 and 0x0001 is set or not.

I’m lost with this. Thanks.


I’ve inspected some of the files in a Hex editor and what i’ve seen is that 11th and 12th bytes need to be read together. That’s why the specs list all the bit flags are 4 letter hex codes. Checking the bit flags individually yields incorrect results.


Assimilating as much information from the answers/tips, ‘ve solved this in the following way:

FileInputStream fisFileInputStream = new FileInputStream((new File("C:\\testarchive.r00"));

byte[] bytHeader = new byte[20]; //The first 20 bytes are the RAR header.
fisFileInputStream.read(bytHeader);

short val=(short)( ((bytHeader[10]&0xFF)<<8) | (bytHeader[11]&0xFF) ); //Joining the two bytes into a short

System.out.println("Volume Attribute (0x0001): " + ((val & 0x0001) != 0));
System.out.println("First volume (0x0100): " + ((val & 0x0100) != 0));

I’ve tried this code with multiple RAR archives — spanned ones, non-spanned ones, the first file of a spanned archive, another file of a spanned archive.

The code itself works fine except for a very minor quirk. I get the opposite results from my hex values i.e.

When inspecting a file which is not the first file in a spanned archive, I get the volume atrribute 0x0001 as not set (false), and the "First volume" 0x100 as set (true).

When inspecting a file which is the first file in a spanned archive, I get the exact opposite results.

Now I modify my code to believe that the original specs are wrong (highly unlikely) and that 0x0001 means that is is the first file in a spanned archive and 0x0100 means that is a spanned archive, then it’s all okay.

..but I guess I’m doing something wrong here with my bit flag logic. Any ideas?

  • 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-07T07:36:24+00:00Added an answer on June 7, 2026 at 7:36 am

    The idea of bit flags is that you can cram a bunch of flags into a small number of bytes by adding them together.

    In this case, they’re not saying that each value you see in that list is a separate pair of bytes. They’re all crammed into two bytes. If you were writing the file, you would add these values together to get the value to write.

    For example, suppose we want to say “Archive lock attribute”, “New volume naming scheme”, and “Block headers encrypted”. That means we want to set 0x0004, 0x0010, and 0x0080. So we add these all together, 0x0004 + 0x0010 + 0x0080 = 0x0094, and that’s the value we write. For this to work, all values must turn out to be a single bit, or to put it another way, all must be powers of 2.

    So this documentation doesn’t describe 18 bytes. It only describes 2.

    To read it, you have to perform AND operations (&) with the desired flag value. Life if you want to know if “Block headers encrypted” is set, read the value and AND with 0x0010. As this is a two-byte value, you either want to get it into a short or you have to pick the correct byte. Let’s say for the sake of argument that we get it into a short. Then we’d say

    if ((flags & 0x0010) != 0)
    

    If that expression is true, then the bit is set. If it is false, the bit is not set.

    BTW, if you read it as a stream of bytes, you can put them into a short by writing:

    short flags = b[0] | b[1]<<8;
    

    (You may need a cast in there. I forget.)

    Or you may have to switch b[0] and b[1], depending on whether the file is written low-hi or hi-low.

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

Sidebar

Related Questions

I'm parsing an XML file, the creators of it stuck in a bunch social
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

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.