Turn off the rightmost set bit

Here given code implementation process.

// C program for
// Turn off the rightmost set bit
#include <stdio.h>

// Returns a unsets view of right most bit
int unSetBit(int num)
{
    return num & (num - 1);
}
// Handles the request of unset the rightmost bit of a number
void changeActiveRightMost(int num)
{
    printf(" Number : %d\n", num);
    printf(" After change of rightmost active bit : %d\n\n", unSetBit(num));
}
int main()
{
    // 1010
    changeActiveRightMost(10);
    //1111
    changeActiveRightMost(15);
    //101000000
    changeActiveRightMost(320);
    return 0;
}

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256
/*
  Java Program for
  Turn off the rightmost set bit
*/
class BitLogic
{
    // Returns a un set view of right most active bit
    public int unSetBit(int num)
    {
        return num & (num - 1);
    }
    // Handles the request of unset the active rightmost bit of a number
    public void changeActiveRightMost(int num)
    {
        System.out.print(" Number : " + num + "\n");
        System.out.print(" After change of rightmost active bit : " + unSetBit(num) + "\n\n");
    }
    public static void main(String[] args)
    {
        BitLogic task = new BitLogic();
        // 1010
        task.changeActiveRightMost(10);
        // 1111
        task.changeActiveRightMost(15);
        // 101000000
        task.changeActiveRightMost(320);
    }
}

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256
// Include header file
#include <iostream>

using namespace std;
/*
  C++ Program for
  Turn off the rightmost set bit
*/
class BitLogic
{
    public:
        // Returns a un set view of right most active bit
        int unSetBit(int num)
        {
            return num &(num - 1);
        }
    // Handles the request of unset the active rightmost bit of a number
    void changeActiveRightMost(int num)
    {
        cout << " Number : " << num << "\n";
        cout << " After change of rightmost active bit : " << this->unSetBit(num) << "\n\n";
    }
};
int main()
{
    BitLogic task = BitLogic();
    // 1010
    task.changeActiveRightMost(10);
    // 1111
    task.changeActiveRightMost(15);
    // 101000000
    task.changeActiveRightMost(320);
    return 0;
}

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256
// Include namespace system
using System;
/*
  C# Program for
  Turn off the rightmost set bit
*/
public class BitLogic
{
    // Returns a un set view of right most active bit
    public int unSetBit(int num)
    {
        return num & (num - 1);
    }
    // Handles the request of unset the active rightmost bit of a number
    public void changeActiveRightMost(int num)
    {
        Console.Write(" Number : " + num + "\n");
        Console.Write(" After change of rightmost active bit : " + unSetBit(num) + "\n\n");
    }
    public static void Main(String[] args)
    {
        BitLogic task = new BitLogic();
        // 1010
        task.changeActiveRightMost(10);
        // 1111
        task.changeActiveRightMost(15);
        // 101000000
        task.changeActiveRightMost(320);
    }
}

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256
<?php
/*
  Php Program for
  Turn off the rightmost set bit
*/
class BitLogic
{
    // Returns a un set view of right most active bit
    public  function unSetBit($num)
    {
        return $num & ($num - 1);
    }
    // Handles the request of unset the active rightmost bit of a number
    public  function changeActiveRightMost($num)
    {
        echo " Number : ". $num ."\n";
        echo " After change of rightmost active bit : ". $this->unSetBit($num) ."\n\n";
    }
}

function main()
{
    $task = new BitLogic();
    // 1010
    $task->changeActiveRightMost(10);
    // 1111
    $task->changeActiveRightMost(15);
    // 101000000
    $task->changeActiveRightMost(320);
}
main();

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256
/*
  Node Js Program for
  Turn off the rightmost set bit
*/
class BitLogic
{
    // Returns a un set view of right most active bit
    unSetBit(num)
    {
        return num & (num - 1);
    }
    // Handles the request of unset the active rightmost bit of a number
    changeActiveRightMost(num)
    {
        process.stdout.write(" Number : " + num + "\n");
        process.stdout.write(" After change of rightmost active bit : " + this.unSetBit(num) + "\n\n");
    }
}

function main()
{
    var task = new BitLogic();
    // 1010
    task.changeActiveRightMost(10);
    // 1111
    task.changeActiveRightMost(15);
    // 101000000
    task.changeActiveRightMost(320);
}
main();

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256
#   Python 3 Program for
#   Turn off the rightmost set bit

class BitLogic :
    #  Returns a un set view of right most active bit
    def unSetBit(self, num) :
        return num & (num - 1)
    
    #  Handles the request of unset the active rightmost bit of a number
    def changeActiveRightMost(self, num) :
        print(" Number : ", num )
        print(" After change of rightmost active bit : ", self.unSetBit(num) ,"\n")
    

def main() :
    task = BitLogic()
    #  1010
    task.changeActiveRightMost(10)
    #  1111
    task.changeActiveRightMost(15)
    #  101000000
    task.changeActiveRightMost(320)

if __name__ == "__main__": main()

Output

 Number :  10
 After change of rightmost active bit :  8

 Number :  15
 After change of rightmost active bit :  14

 Number :  320
 After change of rightmost active bit :  256
#   Ruby Program for
#   Turn off the rightmost set bit

class BitLogic 
    #  Returns a un set view of right most active bit
    def unSetBit(num) 
        return num & (num - 1)
    end

    #  Handles the request of unset the active rightmost bit of a number
    def changeActiveRightMost(num) 
        print(" Number : ", num ,"\n")
        print(" After change of rightmost active bit : ", self.unSetBit(num) ,"\n\n")
    end

end

def main() 
    task = BitLogic.new()
    #  1010
    task.changeActiveRightMost(10)
    #  1111
    task.changeActiveRightMost(15)
    #  101000000
    task.changeActiveRightMost(320)
end

main()

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256

/*
  Scala Program for
  Turn off the rightmost set bit
*/
class BitLogic
{
    // Returns a un set view of right most active bit
    def unSetBit(num: Int): Int = {
        return num & (num - 1);
    }
    // Handles the request of unset the active rightmost bit of a number
    def changeActiveRightMost(num: Int): Unit = {
        print(" Number : " + num + "\n");
        print(" After change of rightmost active bit : " + this.unSetBit(num) + "\n\n");
    }
}
object Main
{
    def main(args: Array[String]): Unit = {
        var task: BitLogic = new BitLogic();
        // 1010
        task.changeActiveRightMost(10);
        // 1111
        task.changeActiveRightMost(15);
        // 101000000
        task.changeActiveRightMost(320);
    }
}

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256
/*
  Swift 4 Program for
  Turn off the rightmost set bit
*/
class BitLogic
{
    // Returns a un set view of right most active bit
    func unSetBit(_ num: Int)->Int
    {
        return num & (num - 1);
    }
    // Handles the request of unset the active rightmost bit of a number
    func changeActiveRightMost(_ num: Int)
    {
        print(" Number : ", num );
        print(" After change of rightmost active bit : ", self.unSetBit(num) ,"\n");
    }
}
func main()
{
    let task: BitLogic = BitLogic();
    // 1010
    task.changeActiveRightMost(10);
    // 1111
    task.changeActiveRightMost(15);
    // 101000000
    task.changeActiveRightMost(320);
}
main();

Output

 Number :  10
 After change of rightmost active bit :  8

 Number :  15
 After change of rightmost active bit :  14

 Number :  320
 After change of rightmost active bit :  256
/*
  Kotlin Program for
  Turn off the rightmost set bit
*/
class BitLogic
{
    // Returns a un set view of right most active bit
    fun unSetBit(num: Int): Int
    {
        return num and(num - 1);
    }
    // Handles the request of unset the active rightmost bit of a number
    fun changeActiveRightMost(num: Int): Unit
    {
        print(" Number : " + num + "\n");
        print(" After change of rightmost active bit : " + this.unSetBit(num) + "\n\n");
    }
}
fun main(args: Array < String > ): Unit
{
    var task: BitLogic = BitLogic();
    // 1010
    task.changeActiveRightMost(10);
    // 1111
    task.changeActiveRightMost(15);
    // 101000000
    task.changeActiveRightMost(320);
}

Output

 Number : 10
 After change of rightmost active bit : 8

 Number : 15
 After change of rightmost active bit : 14

 Number : 320
 After change of rightmost active bit : 256


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved