# Multiply a number by 4 using bitwise operator

Here given code implementation process.

```
// C Program
// Multiply a number by 4 using bitwise operator
#include <stdio.h>
void multiplyBy4(int num)
{
// Shift given number to left by 2
int result = ((num) << 2);
// Display calculated result
printf(" (%d x 4) %d\n", num, result);
}
int main()
{
// Test
multiplyBy4(6);
multiplyBy4(10);
multiplyBy4(7);
multiplyBy4(-3);
return 0;
}
```

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

```
/*
Java program
Multiply a number by 4 using bitwise operator
*/
public class Multiplication
{
public void multiplyBy4(int num)
{
// Shift given number to left by 2
int result = ((num) << 2);
// Display calculated result
System.out.println(" (" + num + " x 4) " + result);
}
public static void main(String[] args)
{
Multiplication task = new Multiplication();
// Test
task.multiplyBy4(6);
task.multiplyBy4(10);
task.multiplyBy4(7);
task.multiplyBy4(-3);
}
}
```

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

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

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

```
// Include namespace system
using System;
/*
Csharp program
Multiply a number by 4 using bitwise operator
*/
public class Multiplication
{
public void multiplyBy4(int num)
{
// Shift given number to left by 2
int result = ((num) << 2);
// Display calculated result
Console.WriteLine(" (" + num + " x 4) " + result);
}
public static void Main(String[] args)
{
Multiplication task = new Multiplication();
// Test
task.multiplyBy4(6);
task.multiplyBy4(10);
task.multiplyBy4(7);
task.multiplyBy4(-3);
}
}
```

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

```
package main
import "fmt"
/*
Go program
Multiply a number by 4 using bitwise operator
*/
func multiplyBy4(num int) {
// Shift given number to left by 2
var result int = ((num) << 2)
// Display calculated result
fmt.Println("(", num, "x 4 )", result)
}
func main() {
// Test
multiplyBy4(6)
multiplyBy4(10)
multiplyBy4(7)
multiplyBy4(-3)
}
```

#### Output

```
( 6 x 4 ) 24
( 10 x 4 ) 40
( 7 x 4 ) 28
( -3 x 4 ) -12
```

```
<?php
/*
Php program
Multiply a number by 4 using bitwise operator
*/
class Multiplication
{
public function multiplyBy4($num)
{
// Shift given number to left by 2
$result = (($num) << 2);
// Display calculated result
echo(" (".$num.
" x 4) ".$result.
"\n");
}
}
function main()
{
$task = new Multiplication();
// Test
$task->multiplyBy4(6);
$task->multiplyBy4(10);
$task->multiplyBy4(7);
$task->multiplyBy4(-3);
}
main();
```

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

```
/*
Node JS program
Multiply a number by 4 using bitwise operator
*/
class Multiplication
{
multiplyBy4(num)
{
// Shift given number to left by 2
var result = ((num) << 2);
// Display calculated result
console.log(" (" + num + " x 4) " + result);
}
}
function main()
{
var task = new Multiplication();
// Test
task.multiplyBy4(6);
task.multiplyBy4(10);
task.multiplyBy4(7);
task.multiplyBy4(-3);
}
main();
```

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

```
# Python 3 program
# Multiply a number by 4 using bitwise operator
class Multiplication :
def multiplyBy4(self, num) :
# Shift given number to left by 2
result = ((num) << 2)
# Display calculated result
print(" (", num ," x 4) ", result)
def main() :
task = Multiplication()
# Test
task.multiplyBy4(6)
task.multiplyBy4(10)
task.multiplyBy4(7)
task.multiplyBy4(-3)
if __name__ == "__main__": main()
```

#### Output

```
( 6 x 4) 24
( 10 x 4) 40
( 7 x 4) 28
( -3 x 4) -12
```

```
# Ruby program
# Multiply a number by 4 using bitwise operator
class Multiplication
def multiplyBy4(num)
# Shift given number to left by 2
result = ((num) << 2)
# Display calculated result
print(" (", num ," x 4) ", result, "\n")
end
end
def main()
task = Multiplication.new()
# Test
task.multiplyBy4(6)
task.multiplyBy4(10)
task.multiplyBy4(7)
task.multiplyBy4(-3)
end
main()
```

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

```
/*
Scala program
Multiply a number by 4 using bitwise operator
*/
class Multiplication()
{
def multiplyBy4(num: Int): Unit = {
// Shift given number to left by 2
var result: Int = ((num) << 2);
// Display calculated result
println(" (" + num + " x 4) " + result);
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Multiplication = new Multiplication();
// Test
task.multiplyBy4(6);
task.multiplyBy4(10);
task.multiplyBy4(7);
task.multiplyBy4(-3);
}
}
```

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

```
/*
Swift 4 program
Multiply a number by 4 using bitwise operator
*/
class Multiplication
{
func multiplyBy4(_ num: Int)
{
// Shift given number to left by 2
let result: Int = ((num) << 2);
// Display calculated result
print(" (", num ," x 4) ", result);
}
}
func main()
{
let task: Multiplication = Multiplication();
// Test
task.multiplyBy4(6);
task.multiplyBy4(10);
task.multiplyBy4(7);
task.multiplyBy4(-3);
}
main();
```

#### Output

```
( 6 x 4) 24
( 10 x 4) 40
( 7 x 4) 28
( -3 x 4) -12
```

```
/*
Kotlin program
Multiply a number by 4 using bitwise operator
*/
class Multiplication
{
fun multiplyBy4(num: Int): Unit
{
// Shift given number to left by 2
val result: Int = ((num) shl 2);
// Display calculated result
println(" (" + num + " x 4) " + result);
}
}
fun main(args: Array < String > ): Unit
{
val task: Multiplication = Multiplication();
// Test
task.multiplyBy4(6);
task.multiplyBy4(10);
task.multiplyBy4(7);
task.multiplyBy4(-3);
}
```

#### Output

```
(6 x 4) 24
(10 x 4) 40
(7 x 4) 28
(-3 x 4) -12
```

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