Multiply a number by 10 using bitwise operator

Here given code implementation process.

// C Program
// Multiply a number by 10 using bitwise operator
#include <stdio.h>

void multiplyBy10(int num)
{
	// Addition of
	// Shift the number to the left by 3
	// Shift the number to the left by 1
	int result = ((num) << 3) + ((num) << 1);
	// Display calculated result
	printf(" (%d x 10) %d\n", num, result);
}
int main()
{
	// Test
	multiplyBy10(6);
	multiplyBy10(10);
	multiplyBy10(7);
	multiplyBy10(-3);
	return 0;
}

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
/*
    Java program
    Multiply a number by 10 using bitwise operator
*/
public class Multiplication
{
	public void multiplyBy10(int num)
	{
		// Addition of
		// Shift the number to the left by 3
		// Shift the number to the left by 1
		int result = ((num) << 3) + ((num) << 1);
		// Display calculated result
		System.out.println(" (" + num + " x 10) " + result);
	}
	public static void main(String[] args)
	{
		Multiplication task = new Multiplication();
		// Test
		task.multiplyBy10(6);
		task.multiplyBy10(10);
		task.multiplyBy10(7);
		task.multiplyBy10(-3);
	}
}

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
// Include header file
#include <iostream>
using namespace std;
/*
    C++ program
    Multiply a number by 10 using bitwise operator
*/
class Multiplication
{
	public: void multiplyBy10(int num)
	{
		// Addition of
		// Shift the number to the left by 3
		// Shift the number to the left by 1
		int result = ((num) << 3) + ((num) << 1);
		// Display calculated result
		cout << " (" << num << " x 10) " << result << endl;
	}
};
int main()
{
	Multiplication *task = new Multiplication();
	// Test
	task->multiplyBy10(6);
	task->multiplyBy10(10);
	task->multiplyBy10(7);
	task->multiplyBy10(-3);
	return 0;
}

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
// Include namespace system
using System;
/*
    Csharp program
    Multiply a number by 10 using bitwise operator
*/
public class Multiplication
{
	public void multiplyBy10(int num)
	{
		// Addition of
		// Shift the number to the left by 3
		// Shift the number to the left by 1
		int result = ((num) << 3) + ((num) << 1);
		// Display calculated result
		Console.WriteLine(" (" + num + " x 10) " + result);
	}
	public static void Main(String[] args)
	{
		Multiplication task = new Multiplication();
		// Test
		task.multiplyBy10(6);
		task.multiplyBy10(10);
		task.multiplyBy10(7);
		task.multiplyBy10(-3);
	}
}

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
package main
import "fmt"
/*
    Go program
    Multiply a number by 10 using bitwise operator
*/

func multiplyBy10(num int) {
	// Addition of
	// Shift the number to the left by 3
	// Shift the number to the left by 1
	var result int = ((num) << 3) + ((num) << 1)
	// Display calculated result
	fmt.Printf("(%d x 10 ) %d \n",num, result)
}
func main() {
	
	// Test
	multiplyBy10(6)
	multiplyBy10(10)
	multiplyBy10(7)
	multiplyBy10(-3)
}

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
<?php
/*
    Php program
    Multiply a number by 10 using bitwise operator
*/
class Multiplication
{
	public	function multiplyBy10($num)
	{
		// Addition of
		// Shift the number to the left by 3
		// Shift the number to the left by 1
		$result = (($num) << 3) + (($num) << 1);
		// Display calculated result
		echo(" (".$num.
			" x 10) ".$result.
			"\n");
	}
}

function main()
{
	$task = new Multiplication();
	// Test
	$task->multiplyBy10(6);
	$task->multiplyBy10(10);
	$task->multiplyBy10(7);
	$task->multiplyBy10(-3);
}
main();

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
/*
    Node JS program
    Multiply a number by 10 using bitwise operator
*/
class Multiplication
{
	multiplyBy10(num)
	{
		// Addition of
		// Shift the number to the left by 3
		// Shift the number to the left by 1
		var result = ((num) << 3) + ((num) << 1);
		// Display calculated result
		console.log(" (" + num + " x 10) " + result);
	}
}

function main()
{
	var task = new Multiplication();
	// Test
	task.multiplyBy10(6);
	task.multiplyBy10(10);
	task.multiplyBy10(7);
	task.multiplyBy10(-3);
}
main();

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
#    Python 3 program
#    Multiply a number by 10 using bitwise operator
class Multiplication :
	def multiplyBy10(self, num) :
		#  Addition of
		#  Shift the number to the left by 3
		#  Shift the number to the left by 1
		result = ((num) << 3) + ((num) << 1)
		#  Display calculated result
		print(" (", num ," x 10) ", result)
	

def main() :
	task = Multiplication()
	#  Test
	task.multiplyBy10(6)
	task.multiplyBy10(10)
	task.multiplyBy10(7)
	task.multiplyBy10(-3)

if __name__ == "__main__": main()

Output

 ( 6  x 10)  60
 ( 10  x 10)  100
 ( 7  x 10)  70
 ( -3  x 10)  -30
#    Ruby program
#    Multiply a number by 10 using bitwise operator
class Multiplication 
	def multiplyBy10(num) 
		#  Addition of
		#  Shift the number to the left by 3
		#  Shift the number to the left by 1
		result = ((num) << 3) + ((num) << 1)
		#  Display calculated result
		print(" (", num ," x 10) ", result, "\n")
	end

end

def main() 
	task = Multiplication.new()
	#  Test
	task.multiplyBy10(6)
	task.multiplyBy10(10)
	task.multiplyBy10(7)
	task.multiplyBy10(-3)
end

main()

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
/*
    Scala program
    Multiply a number by 10 using bitwise operator
*/
class Multiplication()
{
	def multiplyBy10(num: Int): Unit = {
		// Addition of
		// Shift the number to the left by 3
		// Shift the number to the left by 1
		var result: Int = ((num) << 3) + ((num) << 1);
		// Display calculated result
		println(" (" + num + " x 10) " + result);
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Multiplication = new Multiplication();
		// Test
		task.multiplyBy10(6);
		task.multiplyBy10(10);
		task.multiplyBy10(7);
		task.multiplyBy10(-3);
	}
}

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30
/*
    Swift 4 program
    Multiply a number by 10 using bitwise operator
*/
class Multiplication
{
	func multiplyBy10(_ num: Int)
	{
		// Addition of
		// Shift the number to the left by 3
		// Shift the number to the left by 1
		let result: Int = ((num) << 3) + ((num) << 1);
		// Display calculated result
		print(" (", num ," x 10) ", result);
	}
}
func main()
{
	let task: Multiplication = Multiplication();
	// Test
	task.multiplyBy10(6);
	task.multiplyBy10(10);
	task.multiplyBy10(7);
	task.multiplyBy10(-3);
}
main();

Output

 ( 6  x 10)  60
 ( 10  x 10)  100
 ( 7  x 10)  70
 ( -3  x 10)  -30
/*
    Kotlin program
    Multiply a number by 10 using bitwise operator
*/
class Multiplication
{
	fun multiplyBy10(num: Int): Unit
	{
		// Addition of
		// Shift the number to the left by 3
		// Shift the number to the left by 1
		val result: Int = ((num) shl 3) + ((num) shl 1);
		// Display calculated result
		println(" (" + num + " x 10) " + result);
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Multiplication = Multiplication();
	// Test
	task.multiplyBy10(6);
	task.multiplyBy10(10);
	task.multiplyBy10(7);
	task.multiplyBy10(-3);
}

Output

 (6 x 10) 60
 (10 x 10) 100
 (7 x 10) 70
 (-3 x 10) -30

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