Sign Up

Talk Programming , Career, Mental Health, Talk Personal Finance ❤️‍ Post a query and receive responses ✅

Have an account? Sign In


Have an account? Sign In Now

Sign In

Post a query and receive responses. Ask anything, Ask Mitra ❤️‍

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

Sorry, you do not have permission to ask a question, 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

Ask Mitra

Ask Mitra Logo Ask Mitra Logo

Ask Mitra Navigation

  • Home
  • About Us
  • Find Jobs
  • Blogs
    • Add New Blog !
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Ask a Question
  • Home
  • All Categories
  • Find Jobs
  • Points and Swags
    • Badges and Points
    • Ask Mitra Swags
  • Blog
    • Add New Blog !
  • FAQs
  • Community Members 💓
  • About Us
  • Contact Us
Home| Questions|Q 79563
Next
Closed
Rohit S Bhusal
Rohit S BhusalBeginner
Asked: September 4, 20222022-09-04T21:37:06+05:45 2022-09-04T21:37:06+05:45In: —Python

Bitwise Operators VS Logical Operators

I had a small query about the difference between “Logical Operators” and “Bitwise Operators”. So, I was solving a problem where I had to use “and” operator and I had used “&”, which also represents ‘and’. It seemed to be working for the first 2 expressions but didn’t work for the third one and when I changed it to logical, it did work. I looked up for some explanations online, but didn’t help much. Could somebody help me?

code:

num=int(input(“Enter a number: “))
result= num % 2
if result != 0:
    print(“Weird”)
elif result == 0 and 2<= num <= 5:
    print(“Not Weird “)
elif result == 0 and 6<= num <= 20:
    print(“Weird”)
elif result == 0 and num>20:
    print(“Not Weird “)
  • 0
  • 4 4 Answers
  • 64 Views
  • 1 Follower
  • 0
Share
  • Facebook

    Related Questions

    • Hi I am doing my major project using CNN. Can someone help me out? My accuracy is coming to about ...
    • Error: ValueError: could not broadcast input array from shape (420,594,3) into shape (337,284,3)
    • Python
    • Any best free courses of python??
    • Decent IDE for Python

    You must login to add an answer.


    Forgot Password?

    Need An Account, Sign Up Here

    4 Answers

    • Voted
    • Oldest
    • Recent
    • Random
    1. Virtual Wiz Tech Nerd Love to Code | Just a Tech Enthusiast
      2022-09-05T10:46:15+05:45Added an answer on September 5, 2022 at 10:46 am
      This answer was edited.

      Logical AND is represented by &&

      Bitwise AND is represented by &


      The logical AND operator works on Boolean expressions, and returns Boolean values only.

      The bitwise AND operator works on integer, short int, long, unsigned int type data, and also returns that type of data.


      Example:

      
      
      
      
      #include<iostream>
      using namespace std;
      int main() {
         int x = 3; //...0011
         int y = 7; //...0111
         if (y > 1 && y > x)
            cout << "y is greater than 1 AND x" << endl;
         int z = x & y; // 0011
         cout << "z = "<< z;
      }
      
      

      Output:

      y is greater than 1 AND x
      z = 3

      The && operator does not evaluate second operand if first operand becomes false. Similarly, || operator does not evaluate second operand when first one becomes true, but bitwise operators like & and | always evaluate their operands.

      Example:

      
      
      
      
      #include<iostream>
      using namespace std;
      int main() {
         int x = 0;
         cout << (x && printf("Test using && ")) << endl;
         cout << (x & printf("Test using & "));
      }
      
      

      Output:

      0
      Test using & 0

      Hope you understood

      • 1
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. gueneverebetje Sensei
      2022-09-04T21:56:00+05:45Added an answer on September 4, 2022 at 9:56 pm

      Following. Ustai huna parni? Why different? Hopeing to read good answer.

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    3. Tilak_A_W Beginner
      2022-09-04T22:01:24+05:45Added an answer on September 4, 2022 at 10:01 pm

      Hope This will help you.

      https://www.tutorialspoint.com/what-are-the-differences-between-bitwise-and-logical-and-operators-in-c-cplusplus#:~:text=The%20logical%20AND%20operator%20works,returns%20that%20type%20of%20data.

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    4. GD Explainer
      2022-09-28T10:15:20+05:45Added an answer on September 28, 2022 at 10:15 am

      There is a significant difference between bitwise and logical operators. Bitwise operators perform an operation on the bits of a number, while logical operators perform an operation on the truth value of expressions.

      Bitwise operators are typically used for bit manipulation, such as setting, clearing, or toggling individual bits in a number. Logical operators are typically used for Boolean operations, such as AND, OR, and NOT.

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

    Sidebar

    Ask A Question

    Your Favourite Topics

    • Announcements
    • Blockchain
    • Books

        • —Non Tech Books
        • —technical books
    • Business and Entrepreneurship
    • Careers
    • College
    • Content and Blog
    • CyberSecurity
    • Design and Arts
    • Devices and Gadgets
    • Digital Marketing
    • Entertainment

        • —Movies-Series-TV
        • —Music
        • —Sports
    • Events
    • For Admins only.
    • Health

        • —Fitness
    • Money

        • —Personal Finance
        • —Stock Market
    • Operating System

        • —linux
        • —windows
    • Other
    • Paid Internship
    • Programming

        • —AI/ML
        • —APIs
        • —C & C#
        • —Django
        • —Flutter
        • —Go
        • —HTML&CSS
        • —Java
        • —JavaScript
        • —Mobile Apps Development
        • —Node Js
        • —NoSQL
        • —Php
        • —Python
        • —React JS
        • —SQL

    Stats

    • Questions 1k
    • Answers 10k
    • Best Answers 394
    • Users 2k

    Top 6 Members This Month

    Vicky

    Vicky

    • 0 Questions
    • 78 Points
    Sensei
    puppet

    puppet

    • 0 Questions
    • 23 Points
    Beginner
    wtfixair

    wtfixair

    • 0 Questions
    • 22 Points
    Beginner
    Dhanmaya

    Dhanmaya

    • 0 Questions
    • 20 Points
    Beginner
    Riyesh

    Riyesh

    • 0 Questions
    • 20 Points
    Beginner
    pranitkarki

    pranitkarki

    • 0 Questions
    • 20 Points
    Beginner

    Trending Tags

    blockchain c++ career coding College cybersecurity Django Flutter help html javascript laptop laravel linux poll Programming python question react web web development wordpress
    • Popular
    • Answers
    • Rounak Agrawal

      Ask Mitra Udemy Courses Giveaway

      • 76 Answers
    • Subedi Bibek

      The Complete JavaScript Course 2022: From Zero to Expert! Udemy ...

      • 73 Answers
    • Subedi Bibek

      Mega Giveaway at askmitra.com 🔥

      • 69 Answers
    • Sandeep Poudel
      Sandeep Poudel added an answer SOLVED: It was due to unfinished SSL certificate installation January 27, 2023 at 7:11 pm
    • Aashutosh_k
      Aashutosh_k added an answer Software piracy protection system Fingerprint voting system Stock price prediction… January 26, 2023 at 7:37 pm
    • Sangam AKA Ronnie
      Sangam AKA Ronnie added an answer Did you miss my video. https://youtu.be/Wo0NxEivd7A watch at end to… January 24, 2023 at 9:13 pm

    Related Questions

    • Hi I am doing my major project using CNN. Can ...

      • 0 Answers
    • Error: ValueError: could not broadcast input array from shape (420,594,3) ...

      • 3 Answers
    • Python

      • 7 Answers
    • Any best free courses of python??

      • 1 Answer
    • Decent IDE for Python

      • 7 Answers

    Explore

    • Home
    • Trending Category
      • Programming
      • Web Development
      • —Mobile Apps Development
      • —Stock Market
      • Business and Entrepreneurship
      • Blockchain
      • College
      • —Personal Finance
      • —HTML&CSS
      • —JavaScript
      • —Python
      • —React JS
      • —Node Js
      • —C & C#
      • Content and Blog
      • Careers
    • All Categories
      • Go to All Categories
      • Health
      • —Go
      • —Flutter
      • Digital Marketing
      • —APIs
      • Devices and Gadgets
    • Find Job and Internships
    • Points and Swags
      • Badges and Points
      • Ask Mitra Swags
    • All Blogs
      • Add New Blog !
    • FAQs
    • Community Members 💓
    • Questions
      • Un Answered
      • New Questions
      • Most Seen Questions
      • Most Answered
      • Trending Questions
    • Tags

    Footer

    Ask Mitra

    Ask Mitra

    Ask Mitra is a social question and answer engine that will assist you in forming a community and connecting with others. Talk about programming, your career, your mental health, and your personal finances. ❤️‍ Post a query and receive responses ✅

    Quick Navigation

    • Ask a Question
    • Home
    • All Categories
    • Find Jobs
    • Points and Swags
      • Badges and Points
      • Ask Mitra Swags
    • Blog
      • Add New Blog !
    • FAQs
    • Community Members 💓
    • About Us
    • Contact Us

    Legal Stuff

    • Terms of use and policy