ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the bitwise right-shift (>>) operator

Here, we are going to demonstrate the bitwise right-shift (>>) operator in Rust programming language.
Submitted by Nidhi, on September 23, 2021

Problem Solution:

Right shift (>>): The right shift operator (>>) shifts the first operand the specified number of bits to the right. Here, we will perform the bitwise right-shift (>>) operation between two variables and print the result.

Program/Source Code:

The source code to demonstrate the bitwise right-shift (<<) operator is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate the 
// bitwise right-shift ">>" operator

fn main() {
    let mut num1:i32 = 32;
    let mut num2:i32 = 2;
    let mut res:i32  = 0;

    res = num1 >> num2;

    println!("{0} >> {1} = {2}",num1,num2,res);
}

Output:

32 >> 2 = 8

Explanation:

Here, we created three integer variables num1, num2, res that are initialized with 32, 2, 0 respectively. Then we performed a bitwise right shift operation and printed the result.

Evolution of expression:

res = 32 >> 2
res = 32 / (22)
res = 32 / 4
res = 8

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.