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
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
Bitwise Operators in C++
Next article icon

Bitwise Operators in LISP

Last Updated : 29 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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 b
00010011
01011100
11101001
10011100

Different bitwise operators in LISP are listed below in the tabular form

OperatorSyntaxDescription
logand(logand num1 num2)The operator returns bitwise logical AND of two numbers 
logior(logior num1 num2)The operator returns bitwise Inclusive OR of two numbers
logxor(logxor num1 num2)The operator returns bitwise Exclusive OR of two numbers
lognor(lognor num1 num2)The operator returns bitwise NOT of two numbers
logeqv(logeqv num1 num2)The operator returns bitwise Exclusive NOR of two numbers
logcount(logcount num1)The operator returns the number of ones in the binary representation of the integer

 Let’s understand each operator one by one.

  • logand: It takes two numbers as operands and does logical AND on every bit of two numbers and returns it, If no operands are given then the result is -1
a = 5 = 0101 (In Binary)  b = 7 = 0111 (In Binary)    logand Operation of 5 and 7      0101      0111   ________  =    0101  = 5 (In decimal) 
Lisp
;set value of variable val1 to 5 (setq val1 5) ;set value of variable val2 to 7 (setq val2 7)  ;; logand operator (print (logand val1 val2)) 
  • logior: The operator returns bitwise Inclusive OR of the arguments that are passed, If only a single argument is passed it will return the argument itself
a = 5 = 0101 (In Binary)  b = 7 = 0111 (In Binary)    logior Operation of 5 and 7    0101    0111   ________  = 0111  = 7 (In decimal) 
Lisp
;set value of variable val1 to 5 (setq val1 5) ;set value of variable val2 to 7 (setq val2 7)  ;; logior operator (print (logior val1 val2)) 
  • logxor: It returns the bitwise Exclusive OR of its arguments, if no arguments are passed it returns 0
a = 5 = 0101 (In Binary)  b = 7 = 0111 (In Binary)    logxor Operation of 5 and 7    0101  ^ 0111   ________  = 0010  = 2 (In decimal) 
Lisp
;set value of variable val1 to 5 (setq val1 5) ;set value of variable val2 to 7 (setq val2 7)  ;; logxor operator (print (logxor val1 val2)) 
  • lognor: The operator returns bitwise NOT of its arguments, if no arguments are passed it returns -1
a = 5 = 0101 (In Binary)  b = 7 = 0111 (In Binary)    lognor Operation of 5 and 7        0101      0111  _________      = -(1000) = -8 in decimal    
Lisp
;set value of variable val1 to 5 (setq val1 5) ;set value of variable val2 to 7 (setq val2 7)  ;; lognor operator (print (lognor val1 val2)) 
  • logeqv: The operator takes two arguments and does Exclusive Nor(i.e. Logical Equivalence) of those arguments, if no arguments are given then it returns -1
a = 5 = 0101 (In Binary)  b = 7 = 0111 (In Binary)    logeqv Operation of 5 and 7    0101    0111   ________  = 1101         XNOR is just inversion of XOR
Lisp
;set value of variable val1 to 5 (setq val1 5) ;set value of variable val2 to 7 (setq val2 7)  ;; logeqv operator (print (logeqv val1 val2)) 
  • logcount: The operator counts the number of bits in an integer, If the number is positive then 1-bits are counted, if it's negative then 0-bits in two's complement are counted.
a = 7 = 0111 (in Binary)    logcount Operation of 5    = 0111     ^^^    there are three 1-bits        Hence the logcount of 7 will return 3

Example:

Lisp
;set value of variable val1 to 7 (setq val1 7)  ;; logcount operator (print (logcount val1)) 

Shift Operators in LISP

In LISP, for an arithmetic shift, the ash function is used. If the count is positive it shifts the bits to left, else if the count is negative it does the right shift.

Syntax :    ash number count

Example:

sh 10 5;     arithmetic left shift  ash 10 -5;  arithmetic right shift
Lisp
;set value of variable val1 to 10 (setq val1 10) ;set value of variable val2 to 5 (setq val2 5)  ; arithmetic left shift (print (ash val1 val2))       ; arithmetic right shift  (print (ash val1 (- val2)))  

Output : 

320  0

Next Article
Bitwise Operators in C++
author
aniruddhashriwant
Improve
Article Tags :
  • LISP
  • LISP-Basics

Similar Reads

  • 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
  • Operators in LISP
    Operators are the foundation of any programming language. Thus the functionality of the LISP programming language is incomplete without the use of operators. We can define operators as symbols that help us to perform specific mathematical and logical computations on operands. In other words, we can
    5 min read
  • Arithmetic Operators in LISP
    Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division. There are 7 arithmetic operators in LISP that are listed in the below table: OperatorSyntaxDescriptionAddition Operator(+)+ num1 num2Add the two numbersSubtraction Operator(-)-
    2 min read
  • Comparison Operators in LISP
    In this article, we will discuss the comparison operators in LISP. These operators are used to compare numbers by taking two or more operands. Note: This will work only on numbers, Different comparison operators are:OperatorSyntaxNameDescription== operand1 operand2equal toThis operator checks if the
    4 min read
  • Bitwise NOT operator in Golang
    Bitwise NOT operator in the programming world usually takes one number and returns the inverted bits of that number as shown below: Bitwise NOT of 1 = 0 Bitwise NOT of 0 = 1 Example: Input : X = 010101 Output : Bitwise NOT of X = 101010 But Golang doesn't have any specified unary Bitwise NOT(~) or y
    2 min read
  • Vectors in LISP
    In this article, we will discuss Vectors in LISP. Vectors in LISP are one-dimensional arrays which are also known as sequences. We can create a vector using vector function and # symbol Syntax: variable_name(vector element1 element2 ... element n) or variable_name #(element1 element2 ... element n)
    2 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
  • Tensor Bitwise operations
    Tensor bitwise operations in Python involve performing logical operations at the bit level on tensors, which are multi-dimensional arrays widely used in machine learning and deep learning frameworks like TensorFlow and PyTorch. These operations enable the manipulation of binary data efficiently, ess
    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
  • 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?
    5 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.

What kind of Experience do you want to share?

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