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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:30:17+00:00 2026-05-31T05:30:17+00:00

I have to do Boolean operation like, B1=00 10 11 01 00 B2=00 10

  • 0

I have to do Boolean operation like,

 B1=00 10 11 01 00 
 B2=00 10 11 01  
 B1 NOR B2 =11 11 11 11

How is it possible in Java ? Can anybody help ?

Sorry, I forgot to mention, is it possible in Java to perform this bit wise NOR operation from the left always without shifting (B2 has less bits) ?

  • 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-05-31T05:30:18+00:00Added an answer on May 31, 2026 at 5:30 am

    If b1 and b2 are your (int) variables, the expression would be:

    ~(b1 | b2)
    

    For more info, see Bitwise and Bit Shift Operators.

    However, in your example the variables have different lengths. The result doesn’t correspond to a NOR either.

    Update: if you have two sequences of boolean values, no equal size, and only need a portion of it (left to right), I’d suggest using a BitSet:

    BitSet b1 = new BitSet();
    // Fill it with booleans:
    for ( int i = 0 ; i < myBooleans.length ; i++ )
        b1.set(i, myBooleans[i]);
    // Or fill it with bytes:
    BitSet b1 = BitSet.valueOf(myBytes);
    // Or fill it with 0/1 from a string:
    for ( int i = 0 ; i < myString.length() ; i++ )
        b1.set(i, myString.charAt(i) == "1");
    
    BitSet b2 = new BitSet();
    // Same as above
    
    BitSet result = new BitSet();
    result.or(b1); // Copies b1
    result.or(b2); // Makes the OR
    result.flip(0,result.size()); // Negates - the result is a NOR
    result.clear(Math.min(b1.size(), b2.size()), result.size()); // Only retain the common size
    

    If you really want to use int, then it’s better to represent it right to left (i.e. the first bit is b % 2, the second is b / 2 % 2, etc. Then you just have to do the NOR as explained in the beginning, and if necessary truncate the result.

    If they are represented left to right, I believe a shift will be necessary (or a multiplication/division, which is essentially the same thing, but more expensive…), unless they are padded with 0’s (ex.: B1=0010 1101 0000 0000 0000 0000 0000 0000, B2=0010 1101 0000 0000 0000 0000 0000 0000). In this case you can do the operation normally.

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

Sidebar

Related Questions

I have always written my boolean expressions like this: if (!isValid) { // code
I have a text file like this: settings:value data:integer:boolean data:integer:boolean data:integer:boolean data:integer:boolean ... I
Why isn't Collection.remove(Object o) generic? Seems like Collection<E> could have boolean remove(E o); Then,
If I have a boolean field like: private static final boolean DEBUG = false;
This may seem a very silly question. Consider this: I have a simple Boolean
I have this two functions: procedure TDisplay.CubAssign(VAR Obj: TCubObj; CONST bReleaseOnExit: boolean); begin ReleaseCubOnExit:=
/*I have defined Extension Methods for the TypeX like this*/ public static Int32 GetValueAsInt(this
I have a struct like this: public struct MyStruct { public string Name; public
I have a boolean variable declared at the top of a class and when
I have a boolean (BOOL) type field in the SQLite table. In the SubSonic

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.