Reversing the bits of an integer

Reversing the bits of an integer means to flip the order of the bits in its binary representation. For example, if you have a 32-bit integer, reversing the bits would mean the bit at position 0 (rightmost bit) moves to position 31 (leftmost bit), the bit at position 1 moves to position 30, and so … Read more

Detecting Power of Two

Detecting whether a given number is a power of two using bit manipulation is an efficient technique that leverages the properties of binary representation. A number is a power of two if it has exactly one bit set in its binary representation. For example, 2 (binary 10), 4 (binary 100), and 8 (binary 1000) are … Read more

Counting bits or Hamming Weight

Counting bits, also known as the “Hamming Weight” or the “population count”, refers to counting the number of 1 bits in the binary representation of a number. This is a common problem in computer science, often used in various applications such as cryptography, algorithms, and network address calculation. In Kotlin, you can solve the counting … Read more

Swap Two variable using Bit Manipulation

Swapping two numbers using bit manipulation involves a technique that makes use of XOR (^) operator. The XOR operator has a unique property where if you XOR any number with itself, the result is 0, and if you XOR any number with 0, the result is the number itself. This property allows swapping without a … Read more

Linear Search In Kotlin

Linear search, also known as sequential search, is a simple search algorithm that searches an array or list of elements sequentially from the beginning to the end. It compares each element of the array or list with the target element until a match is found or until all the elements have been searched. In linear … Read more

Pattern Printing in Kotlin.

What is pattern ? Pattern printing is a common exercise in programming and is useful for building logic and understanding loops. Pattern printing involves printing out various shapes or figures made up of symbols such as asterisks or spaces. There are several different types of pattern printing, including right triangles, pyramids, diamonds, and many more. … Read more

What is Queue and how it works ?

I assume you are referring to a data structure called a “queue”. A queue is a linear data structure that follows a First-In-First-Out (FIFO) order, which means that the element added first to the queue is the first one to be removed. The main operations of a queue are: A queue can be implemented using … Read more

Stack in Kotlin And how it works

A stack is a fundamental data structure that stores and retrieves elements in a specific order. It is also known as a Last-In-First-Out (LIFO) data structure, which means that the element added last to the stack is the first one to be removed. The main operations of a stack are: A stack can be implemented … Read more

Tower of hanoi in Kotlin

What is Tower of Hanoi and How it works ? The Tower of Hanoi is a mathematical puzzle consisting of three rods and a number of disks of different sizes, which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the … Read more

Taking User Input in Kotlin

To take the user input we import java file “java.util.Scanner” Now in main function make a variable which will store a function calling as “Scanner(System.`in`)” Now to take input in variable as : 1 Int type : 2 String type :