This video tutorial covers Rust's operator categories: arithmetic operators (+, -, *, /, %) where integer division truncates decimals and the remainder operator differs from mathematical mod by preserving sign; boolean operators (&&, ||, !) for logical operations; and bitwise operators (&, |, ^, ~, <<, >>) for binary-level manipulation, with practical examples demonstrating each operator's behavior in Rust code.
Rust Operators Explained: Math, Bitwise, and Boolean Operations
Added:let's look at some operators that are available in Rust we won't go through all of them here I'll just highlight some of them so let's start with some math operators let's say that we have some variables let say a up type i32 = to 1 and B also up type i32 with the value equal to two so let's start with the simple boring ones we can add these two numbers let's say that c again up type i32 = to a plus b or we can subract them say C is equal to a minus B you don't have to worry about underflow over here since we're dealing with i32 signed integers so it can store negative numbers okay and we can also multiply them so let's say that c is equal to a * B then we have division one thing you need to be aware of about division is that division rounds down so for example if you divide two / by 3 then usually you get some number and some decimal numbers after that harb and rust when you divide integers that decimal part gets cut off so for example here we're dividing 1 by two if you punch 1 / two into your calculator you'll get 0.5 however when you're dealing with integers that decimal Parts gets cut off so what you're going to see is that you're going to get zero okay to show you this let's say print Ln say a / B is equal to C run the code cargo run-- bin the name of the file is called operators okay execute and we get 1 / 2 is equal to0 Z what you're seeing here is numbers being round down okay let's move on the remainder the remainder operator is not equal to the mod operator that you might be familiar with from math in a mathematical sense the mod operator let's say we do a mod b and we get some number R then this R will be between zero this R will be between zero and less than b so for example if you do minus1 mod 2 then this will be equal to 1 so this is the mod operator the remainder operator which is implemented in Russ the remainder operator it's going to return the remainder when a is divided by B and for this example minus1 and two the remainder will be minus one so in Rust what you're going to see is minus1 mod 2 is equal to minus1 so see the difference here in a mathematical sense the mod operator will always be a positive number between zero and less than b however in Rust when this remainder operator you're going to get - 1 and to show you this let's say that a is equal to -1 and B is equal to 2 then let's say that REM is equal to a mod b then let's print this out execute the code and we get minus1 the mod Operator 2 is equal to minus1 so this is one thing you should be aware of when you're using this remainder operator next let's take a look at the rules when we're dealing with the rules let's say that a is equal to 1 this one can be of type signed integer 32 or it can be of unsigned integer 32 to be explicit you can tell rust hey I want this number to be of type i32 you do this by after putting in your number you would declare the type so this would be i32 and if you want another number let's say B let's change this number to let's say three and you want this number to be u64 and then you say u64 you can also use the scientific notation so let's say that C is equal to 1.23 E3 and this will be equal to 1.23 * 10 to the 3 which is equal to 1,230 another thing that you can do with leral is make it easier to read when you have a large number so let's say that D is equal to one followed by a lot of zeros okay here it is so it's difficult to tell what what this number is one way you can increase the readability is by adding underscores and now now you can easily see that this number represents a billion okay next let's move on to booleans the Boolean operators that are available in RAR and or and not so let's say that a is equal to you can say true and false or you can say true or false or you can do the not operator so let's say that a equals not true okay finally let's look at some bitwise operators so let's say that a is equal to five of type u8 and then let's create another one B of type u8 and let's make b equal to 3 in binary the first number a will be equal to 1 1 and the second number will be equal to 0 1 1 okay let's look at some operators so first we have and operator A and B this will return a number where in the binary representation when both of the binary representation is equal to one at that position then it will return a one otherwise that position will be a zero say print Ln and here's a trick to print this number as binary say callon 03b let's also print the result of bit yor execute the code and we get a and b is 01 and A or B is equal to 111 next let's take a look at exclusive or with a carot sign execute the code and we get exclusive or is 110 okay and then we also have the negation the not operator let's say not a not a excape the code and we get not a is equal to 1 1 1 1 1 0 1 0 the number is a u8 so you have eight bits and then we have the bit shift operator for example we can say 1 u32 shifted to the left by three okay print this out execute the code and we get one shifted to the left three times is equal to 8 or we can see this in binary representation execute the code again and we get one shifted three times to the left is in binary 1 Follow by 3 zeros okay and we can also shift this number to the right how about we shift 10 to the right two times so this will be 10 you let's say 32 shift it twice to the right print this to print this then execute the code and we get 10 shifted to the right twice is equal to two Okay so these are some examples of operators that are available in Rust
Up Next

Chip-8 Emulator Basics: Architecture, Memory, and Display Explained
@dragonzapeducation
1.3K views•2020-03-12

Introduction to Secure Multiparty Computation with Yehuda Lindell
@fhe_org
7.7K views•2021-02-04

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science




![Learn Rust Programming [Day 1] -- LIVE!](https://i.ytimg.com/vi/zNpmH2SU2wI/maxresdefault.jpg)


































