Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • GfG 160: Daily DSA
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
  • SQL
  • Web Development
  • System Design
  • Aptitude
  • GfG Premium
Open In App
Next Article:
Program for Bitwise Operators in C, C++, Java, Python, C# & JavaScript
Next article icon

Program for Bitwise Operators in C, C++, Java, Python, C# & JavaScript

Last Updated : 26 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Bitwise operators are fundamental operators used in computer programming for manipulating individual data bits. They operate at the binary level, performing operations on binary data representations. These operators are commonly used in low-level programming, such as device drivers, embedded systems, and cryptography, where manipulation at the bit level is required. They can also be used for optimizing certain algorithms and operations where bitwise manipulation can provide faster execution compared to conventional arithmetic operations.

Table of Content

  • What are Bitwise Operators?
  • Types of Bitwise Operators
  • Bitwise Operator in C
  • Bitwise Operator in C++
  • Bitwise Operator in Java
  • Bitwise Operator in Python
  • Bitwise Operator in C#
  • Bitwise Operator in JavaScript
  • Application of Bitwise Operators
  • Important points about Bitwise Operators

What are Bitwise Operators?

Bitwise operators in programming perform operations at the bit level, manipulating individual bits of binary representations of numbers. These operators are often used in low-level programming, such as embedded systems and device drivers.

Types of Bitwise Operators:

  1. Bitwise AND (&): Compares corresponding bits of two operands. If both bits are 1, the result is 1; otherwise, it's 0.
  2. Bitwise OR (|): Compares corresponding bits of two operands. If either bit is 1, the result is 1; otherwise, it's 0.
  3. Bitwise XOR (^): Compares corresponding bits of two operands. If the bits are different, the result is 1; if they are the same, the result is 0.
  4. Bitwise NOT (~): Flips the bits of its operand. If a bit is 0, it becomes 1, and if it's 1, it becomes 0.
  5. Left Shift (<<): Shifts the bits of its first operand to the left by a number of positions specified by the second operand.
  6. Right Shift (>>): Shifts the bits of its first operand to the right by a number of positions specified by the second operand.

Below is a table summarizing common bitwise operators along with their symbols, description:

OperatorDescription
&Bitwise AND operator
|Bitwise OR operator
^Bitwise XOR (exclusive OR) operator
~Bitwise NOT (complement) operator
<<Bitwise left shift operator
>>Bitwise right shift operator

Bitwise Operator in C:

Here are the implementation of Bitwise Operator in C language:

C
#include 

int main() {
    int num1 = 10; // Binary representation: 1010
    int num2 = 5;  // Binary representation: 0101

    // Bitwise AND (&)
    int result_and = num1 & num2; // Result: 0000 (decimal 0)
    printf("Bitwise AND: %d\n", result_and);

    // Bitwise OR (|)
    int result_or = num1 | num2; // Result: 1111 (decimal 15)
    printf("Bitwise OR: %d\n", result_or);

    // Bitwise XOR (^)
    int result_xor = num1 ^ num2; // Result: 1111 (decimal 15)
    printf("Bitwise XOR: %d\n", result_xor);

    // Bitwise NOT (~) - Unary operator
    int result_not1 = ~num1; // Result: 1111 0101 (decimal -11 in 2's complement)
    printf("Bitwise NOT (num1): %d\n", result_not1);
    
    int result_not2 = ~num2; // Result: 1111 1010 (decimal -6 in 2's complement)
    printf("Bitwise NOT (num2): %d\n", result_not2);

    // Bitwise Left Shift (<<)
    int result_left_shift = num1 << 1; // Result: 10100 (decimal 20)
    printf("Bitwise Left Shift: %d\n", result_left_shift);

    // Bitwise Right Shift (>>)
    int result_right_shift = num1 >> 1; // Result: 0101 (decimal 5)
    printf("Bitwise Right Shift: %d\n", result_right_shift);

    return 0;
}

Output
Bitwise AND: 0
Bitwise OR: 15
Bitwise XOR: 15
Bitwise NOT (num1): -11
Bitwise NOT (num2): -6
Bitwise Left Shift: 20
Bitwise Right Shift: 5


Bitwise Operator in C++:

Here are the implementation of Bitwise Operator in C++ language:

C++
#include 
using namespace std;

int main() {
    int num1 = 10; // Binary representation: 1010
    int num2 = 5;  // Binary representation: 0101

    // Bitwise AND (&)
    int result_and = num1 & num2; // Result: 0000 (decimal 0)
    cout << "Bitwise AND: " << result_and << endl;

    // Bitwise OR (|)
    int result_or = num1 | num2; // Result: 1111 (decimal 15)
    cout << "Bitwise OR: " << result_or << endl;

    // Bitwise XOR (^)
    int result_xor = num1 ^ num2; // Result: 1111 (decimal 15)
    cout << "Bitwise XOR: " << result_xor << endl;

    // Bitwise NOT (~) - Unary operator
    int result_not1 = ~num1; // Result: 1111 0101 (decimal -11 in 2's complement)
    cout << "Bitwise NOT (num1): " << result_not1 << endl;
    
    int result_not2 = ~num2; // Result: 1111 1010 (decimal -6 in 2's complement)
    cout << "Bitwise NOT (num2): " << result_not2 << endl;

    // Bitwise Left Shift (<<)
    int result_left_shift = num1 << 1; // Result: 10100 (decimal 20)
    cout << "Bitwise Left Shift: " << result_left_shift << endl;

    // Bitwise Right Shift (>>)
    int result_right_shift = num1 >> 1; // Result: 0101 (decimal 5)
    cout << "Bitwise Right Shift: " << result_right_shift << endl;

    return 0;
}

Output
Bitwise AND: 0
Bitwise OR: 15
Bitwise XOR: 15
Bitwise NOT (num1): -11
Bitwise NOT (num2): -6
Bitwise Left Shift: 20
Bitwise Right Shift: 5


Bitwise Operator in Java:

Here are the implementation of Bitwise Operator in Java language:

Java
public class Main {
    public static void main(String[] args) {
        int num1 = 10; // Binary representation: 1010
        int num2 = 5;  // Binary representation: 0101

        // Bitwise AND (&)
        int result_and = num1 & num2; // Result: 0000 (decimal 0)
        System.out.println("Bitwise AND: " + result_and);

        // Bitwise OR (|)
        int result_or = num1 | num2; // Result: 1111 (decimal 15)
        System.out.println("Bitwise OR: " + result_or);

        // Bitwise XOR (^)
        int result_xor = num1 ^ num2; // Result: 1111 (decimal 15)
        System.out.println("Bitwise XOR: " + result_xor);

        // Bitwise NOT (~) - Unary operator
        int result_not1 = ~num1; // Result: 1111 0101 (decimal -11 in 2's complement)
        System.out.println("Bitwise NOT (num1): " + result_not1);
        
        int result_not2 = ~num2; // Result: 1111 1010 (decimal -6 in 2's complement)
        System.out.println("Bitwise NOT (num2): " + result_not2);

        // Bitwise Left Shift (<<)
        int result_left_shift = num1 << 1; // Result: 10100 (decimal 20)
        System.out.println("Bitwise Left Shift: " + result_left_shift);

        // Bitwise Right Shift (>>)
        int result_right_shift = num1 >> 1; // Result: 0101 (decimal 5)
        System.out.println("Bitwise Right Shift: " + result_right_shift);
    }
}

Output
Bitwise AND: 0
Bitwise OR: 15
Bitwise XOR: 15
Bitwise NOT (num1): -11
Bitwise NOT (num2): -6
Bitwise Left Shift: 20
Bitwise Right Shift: 5


Bitwise Operator in Python:

Here are the implementation of Bitwise Operator in Python language:

Python
num1 = 10  # Binary representation: 1010
num2 = 5   # Binary representation: 0101

# Bitwise AND (&)
result_and = num1 & num2  # Result: 0000 (decimal 0)
print("Bitwise AND:", result_and)

# Bitwise OR (|)
result_or = num1 | num2  # Result: 1111 (decimal 15)
print("Bitwise OR:", result_or)

# Bitwise XOR (^)
result_xor = num1 ^ num2  # Result: 1111 (decimal 15)
print("Bitwise XOR:", result_xor)

# Bitwise NOT (~) - Unary operator
result_not1 = ~num1  # Result: 1111 0101 (decimal -11 in 2's complement)
print("Bitwise NOT (num1):", result_not1)

result_not2 = ~num2  # Result: 1111 1010 (decimal -6 in 2's complement)
print("Bitwise NOT (num2):", result_not2)

# Bitwise Left Shift (<<)
result_left_shift = num1 << 1  # Result: 10100 (decimal 20)
print("Bitwise Left Shift:", result_left_shift)

# Bitwise Right Shift (>>)
result_right_shift = num1 >> 1  # Result: 0101 (decimal 5)
print("Bitwise Right Shift:", result_right_shift)

Output
('Bitwise AND:', 0)
('Bitwise OR:', 15)
('Bitwise XOR:', 15)
('Bitwise NOT (num1):', -11)
('Bitwise NOT (num2):', -6)
('Bitwise Left Shift:', 20)
('Bitwise Right Shift:', 5)


Bitwise Operator in C#:

Here are the implementation of Bitwise Operator in C# language:

C#
using System;

class MainClass {
    public static void Main (string[] args) {
        int num1 = 10; // Binary representation: 1010
        int num2 = 5;  // Binary representation: 0101

        // Bitwise AND (&)
        int result_and = num1 & num2; // Result: 0000 (decimal 0)
        Console.WriteLine("Bitwise AND: " + result_and);

        // Bitwise OR (|)
        int result_or = num1 | num2; // Result: 1111 (decimal 15)
        Console.WriteLine("Bitwise OR: " + result_or);

        // Bitwise XOR (^)
        int result_xor = num1 ^ num2; // Result: 1111 (decimal 15)
        Console.WriteLine("Bitwise XOR: " + result_xor);

        // Bitwise NOT (~) - Unary operator
        int result_not1 = ~num1; // Result: 1111 0101 (decimal -11 in 2's complement)
        Console.WriteLine("Bitwise NOT (num1): " + result_not1);
        
        int result_not2 = ~num2; // Result: 1111 1010 (decimal -6 in 2's complement)
        Console.WriteLine("Bitwise NOT (num2): " + result_not2);

        // Bitwise Left Shift (<<)
        int result_left_shift = num1 << 1; // Result: 10100 (decimal 20)
        Console.WriteLine("Bitwise Left Shift: " + result_left_shift);

        // Bitwise Right Shift (>>)
        int result_right_shift = num1 >> 1; // Result: 0101 (decimal 5)
        Console.WriteLine("Bitwise Right Shift: " + result_right_shift);
    }
}

Output
Bitwise AND: 0
Bitwise OR: 15
Bitwise XOR: 15
Bitwise NOT (num1): -11
Bitwise NOT (num2): -6
Bitwise Left Shift: 20
Bitwise Right Shift: 5


Bitwise Operator in JavaScript:

Here are the implementation of Bitwise Operator in Javascript language:

JavaScript
let num1 = 10; // Binary representation: 1010
let num2 = 5;  // Binary representation: 0101

// Bitwise AND (&)
let result_and = num1 & num2; // Result: 0000 (decimal 0)
console.log("Bitwise AND:", result_and);

// Bitwise OR (|)
let result_or = num1 | num2; // Result: 1111 (decimal 15)
console.log("Bitwise OR:", result_or);

// Bitwise XOR (^)
let result_xor = num1 ^ num2; // Result: 1111 (decimal 15)
console.log("Bitwise XOR:", result_xor);

// Bitwise NOT (~) - Unary operator
let result_not1 = ~num1; // Result: 1111 0101 (decimal -11 in 2's complement)
console.log("Bitwise NOT (num1):", result_not1);

let result_not2 = ~num2; // Result: 1111 1010 (decimal -6 in 2's complement)
console.log("Bitwise NOT (num2):", result_not2);

// Bitwise Left Shift (<<)
let result_left_shift = num1 << 1; // Result: 10100 (decimal 20)
console.log("Bitwise Left Shift:", result_left_shift);

// Bitwise Right Shift (>>)
let result_right_shift = num1 >> 1; // Result: 0101 (decimal 5)
console.log("Bitwise Right Shift:", result_right_shift);

Output
Bitwise AND: 0
Bitwise OR: 15
Bitwise XOR: 15
Bitwise NOT (num1): -11
Bitwise NOT (num2): -6
Bitwise Left Shift: 20
Bitwise Right Shift: 5


Application of Bitwise Operators:

Bitwise operators are commonly used in various scenarios, including:

  • Setting or clearing specific bits within binary data.
  • Checking the status of flags or bit fields.
  • Extracting or packing values from or into binary data structures.
  • Performing arithmetic operations in a more optimized way when dealing with low-level programming, such as manipulating hardware registers or implementing cryptographic algorithms.

Important points about Bitwise Operators:

  • Bitwise operators work at the binary level, which is the lowest level of data representation in computers.
  • They are typically used in scenarios where fine-grained control over individual bits is necessary, such as low-level programming, cryptography, and hardware interfacing.
  • Understanding bitwise operations is crucial for writing efficient code and implementing certain algorithms.

Conclusion:

Bitwise operators are commonly used in low-level programming, such as device drivers, embedded systems, and cryptography, where manipulation at the bit level is required. They can also be used for optimizing certain algorithms and operations where bitwise manipulation can provide faster execution compared to conventional arithmetic operations.


Next Article
Program for Bitwise Operators in C, C++, Java, Python, C# & JavaScript

S

srinam
Improve
Article Tags :
  • Computer Science Fundamentals

Similar Reads

    Bitwise XOR Operator in Programming
    Bitwise XOR Operator is represented by the caret symbol (^). It is used to perform a bitwise XOR operation on the individual bits of two operands. The XOR operator returns 1 if the corresponding bits in the two operands are different, and 0 if they are the same.Table of Content What is Bitwise XOR?B
    5 min read
    Bitwise OR Operator (|) in Programming
    In programming, Bitwise Operators play a crucial role in manipulating individual bits of data. One of the fundamental bitwise operators is the Bitwise OR operator (|). In this article, we’ll discuss the Bitwise OR operator, its syntax, properties, applications, and optimization techniques, and concl
    5 min read
    Bitwise Left Shift(<<) Operator in Programming
    Bitwise operators play a significant role in manipulating individual bits within binary data. Among these operators, the Bitwise Left Shift (<<) operator is used for shifting the bits of a number to the left by a specified number of positions. In this blog post, we'll explore the definition, s
    5 min read
    Bitwise AND operator in Programming
    In programming, Bitwise Operators play a crucial role in manipulating individual bits of data. One of the fundamental bitwise operators is the Bitwise AND operator (&). In this article, we'll dive deep into what is Bitwise AND operator, its syntax, properties, applications, and optimization tech
    6 min read
    Check if the ith Bit is Set or Not using JavaScript
    Checking if the ith bit is set or not in a binary representation is a common task in programming, especially in scenarios where bitwise operations are utilized. In this article, we'll explore multiple approaches to accomplish this using JavaScript. Given a non-negative integer num and an index i, we
    2 min read
    What is JavaScript >>> Operator and how to use it ?
    The JavaScript >>> represents the zero-fill right shift operator. It is also called the unsigned right-bit shift operator. It comes under the category of Bitwise operators. Bitwise operators treat operands as 32-bit integer numbers and operate on their binary representation. Zero-fill right
    3 min read
    Binary Operators in Programming
    Binary Operators are essential tools in programming that perform operations on pairs of data, enabling tasks like calculations, comparisons, logical operations, and bitwise manipulations. They are fundamental for processing and manipulating data efficiently in computer programs. Table of Content Wha
    14 min read
    Bitwise Operators in C++
    In C+, Bitwise Operators are the operators that are used to perform bit-level operations on the integers. While performing these operations, integers are considered as sequences of binary digits. These operators are useful for low-level programming, system programming, and optimizing performance.C++
    6 min read
    Bitwise Operators in LISP
    In this article, we will discuss the Bitwise operators in LISP. These operators are used to perform the manipulation of individual bits of a number. The truth table for bitwise AND, NAND, OR, XOR, NOR, & XNOR:  aba and b a nand ba or b a xor b a nor b a xnor b00010011010111001110100110011100 Dif
    4 min read
    Bit manipulation in JavaScript
    Bit manipulation in JavaScript refers to the manipulation and operation of individual bits within binary representations of numbers and JavaScript uses 32-bit signed integers for numeric values. It involves using bitwise operators (&, |, ^, ~, <<, >>) to manipulate individual bits of
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

'); // $('.spinner-loading-overlay').show(); let script = document.createElement('script'); script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js'; script.defer = true document.head.appendChild(script); script.onload = function() { suggestionModalEditor() //to add editor in suggestion modal if(loginData && loginData.premiumConsent){ personalNoteEditor() //to load editor in personal note } } script.onerror = function() { if($('.editorError').length){ $('.editorError').remove(); } var messageDiv = $('
').text('Editor not loaded due to some issues'); $('#suggestion-section-textarea').append(messageDiv); $('.suggest-bottom-btn').hide(); $('.suggestion-section').hide(); editorLoaded = false; } }); //suggestion modal editor function suggestionModalEditor(){ // editor params const params = { data: undefined, plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"], } // loading editor try { suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true }) suggestEditorInstance._createEditor("") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } //personal note editor function personalNoteEditor(){ // editor params const params = { data: undefined, plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"], placeholderText: "Description to be......", } // loading editor try { let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true }) notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } var lockedCasesHtml = `You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`; var badgesRequiredHtml = `It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.

However, you can still create improvements through the Pick for Improvement section.`; jQuery('.improve-header-sec-child').on('click', function(){ jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); jQuery('#suggestion-modal-alert').hide(); }); $('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked $('.ContentEditable__root').text(""); $('.suggest-bottom-btn').html("Suggest changes"); $('.thank-you-message').css("display","none"); $('.improve-modal--improvement').hide(); $('.improve-modal--suggestion').show(); $('#suggestion-section-textarea').show(); jQuery('#suggestion-modal-alert').hide(); if(suggestEditorInstance !== null){ suggestEditorInstance.setEditorValue(""); } $('.suggestion-section').css('display', 'block'); jQuery('.suggest-bottom-btn').css("display","block"); }); $('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown if(loginData && loginData.isLoggedIn) { $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status) }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ } $('.improve-modal--improvement').show(); }); const showErrorMessage = (result,statusCode) => { if(!result) return; $('.spinner-loading-overlay:eq(0)').remove(); if(statusCode == 403) { $('.improve-modal--improve-content.error-message').html(result.message); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); return; } } function suggestionCall() { var editorValue = suggestEditorInstance.getValue(); var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() { return $(this).text().trim(); }).get().join(' '); suggest_val = suggest_val.replace(/\s+/g, ' ').trim(); var array_String= suggest_val.split(" ") //array of words var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(editorValue.length <= 2000){ var payload = { "gfg_post_id" : `${post_id}`, "suggestion" : `${editorValue}`, } if(!loginData || !loginData.isLoggedIn) // User is not logged in payload["g-recaptcha-token"] = gCaptchaToken jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify(payload), success:function(data) { if(!loginData || !loginData.isLoggedIn) { grecaptcha.reset(); } jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('.suggest-bottom-btn').css("display","none"); $('#suggestion-section-textarea').hide() $('.thank-you-message').css('display', 'flex'); $('.suggestion-section').css('display', 'none'); jQuery('#suggestion-modal-alert').hide(); }, error:function(data) { if(!loginData || !loginData.isLoggedIn) { grecaptcha.reset(); } jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Minimum 4 Words and Maximum Words limit is 1000."); jQuery('#suggestion-modal-alert').show(); jQuery('.ContentEditable__root').focus(); error_msg = true; } } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Enter atleast four words !"); jQuery('#suggestion-modal-alert').show(); jQuery('.ContentEditable__root').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('.ContentEditable__root').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // script for grecaptcha loaded in loginmodal.html and call function to set the token setGoogleRecaptcha(); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status); }, }); });
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"
Continue without supporting
`; $('body').append(adBlockerModal); $('body').addClass('body-for-ad-blocker'); const modal = document.getElementById("adBlockerModal"); modal.style.display = "block"; } function handleAdBlockerClick(type){ if(type == 'disabled'){ window.location.reload(); } else if(type == 'info'){ document.getElementById("ad-blocker-div").style.display = "none"; document.getElementById("ad-blocker-info-div").style.display = "flex"; handleAdBlockerIconClick(0); } } var lastSelected= null; //Mapping of name and video URL with the index. const adBlockerVideoMap = [ ['Ad Block Plus','https://media.geeksforgeeks.org/auth-dashboard-uploads/abp-blocker-min.mp4'], ['Ad Block','https://media.geeksforgeeks.org/auth-dashboard-uploads/Ad-block-min.mp4'], ['uBlock Origin','https://media.geeksforgeeks.org/auth-dashboard-uploads/ub-blocke-min.mp4'], ['uBlock','https://media.geeksforgeeks.org/auth-dashboard-uploads/U-blocker-min.mp4'], ] function handleAdBlockerIconClick(currSelected){ const videocontainer = document.getElementById('ad-blocker-info-div-gif'); const videosource = document.getElementById('ad-blocker-info-div-gif-src'); if(lastSelected != null){ document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.backgroundColor = "white"; document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.borderColor = "#D6D6D6"; } document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.backgroundColor = "#D9D9D9"; document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.borderColor = "#848484"; document.getElementById('ad-blocker-info-div-name-span').innerHTML = adBlockerVideoMap[currSelected][0] videocontainer.pause(); videosource.setAttribute('src', adBlockerVideoMap[currSelected][1]); videocontainer.load(); videocontainer.play(); lastSelected = currSelected; }

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences