Bitwise Operators

12 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€93.30
List Price:  €130.62
You save:  €37.32
£79.79
List Price:  £111.72
You save:  £31.92
CA$136.51
List Price:  CA$191.13
You save:  CA$54.61
A$152.32
List Price:  A$213.26
You save:  A$60.93
S$135.97
List Price:  S$190.37
You save:  S$54.39
HK$782.61
List Price:  HK$1,095.68
You save:  HK$313.07
CHF 91.14
List Price:  CHF 127.60
You save:  CHF 36.46
NOK kr1,099.65
List Price:  NOK kr1,539.56
You save:  NOK kr439.90
DKK kr695.84
List Price:  DKK kr974.21
You save:  DKK kr278.36
NZ$167.38
List Price:  NZ$234.34
You save:  NZ$66.95
د.إ367.24
List Price:  د.إ514.16
You save:  د.إ146.91
৳10,987.33
List Price:  ৳15,382.71
You save:  ৳4,395.37
₹8,345.51
List Price:  ₹11,684.05
You save:  ₹3,338.54
RM476.90
List Price:  RM667.68
You save:  RM190.78
₦132,499.74
List Price:  ₦185,504.94
You save:  ₦53,005.20
₨27,870.93
List Price:  ₨39,020.42
You save:  ₨11,149.48
฿3,701.15
List Price:  ฿5,181.76
You save:  ฿1,480.61
₺3,236.01
List Price:  ₺4,530.55
You save:  ₺1,294.53
B$511.64
List Price:  B$716.32
You save:  B$204.68
R1,874.13
List Price:  R2,623.86
You save:  R749.72
Лв182.50
List Price:  Лв255.51
You save:  Лв73
₩137,667.26
List Price:  ₩192,739.67
You save:  ₩55,072.41
₪376.30
List Price:  ₪526.84
You save:  ₪150.53
₱5,769.57
List Price:  ₱8,077.63
You save:  ₱2,308.05
¥15,587.34
List Price:  ¥21,822.90
You save:  ¥6,235.56
MX$1,712.57
List Price:  MX$2,397.67
You save:  MX$685.09
QR365.03
List Price:  QR511.06
You save:  QR146.02
P1,378.03
List Price:  P1,929.30
You save:  P551.26
KSh13,498.65
List Price:  KSh18,898.65
You save:  KSh5,400
E£4,784.52
List Price:  E£6,698.52
You save:  E£1,914
ብር5,745.61
List Price:  ብር8,044.09
You save:  ብር2,298.47
Kz83,397.65
List Price:  Kz116,760.05
You save:  Kz33,362.40
CLP$95,071.49
List Price:  CLP$133,103.89
You save:  CLP$38,032.40
CN¥724.13
List Price:  CN¥1,013.82
You save:  CN¥289.68
RD$5,869.02
List Price:  RD$8,216.87
You save:  RD$2,347.84
DA13,441.55
List Price:  DA18,818.71
You save:  DA5,377.16
FJ$225.51
List Price:  FJ$315.73
You save:  FJ$90.21
Q778.65
List Price:  Q1,090.14
You save:  Q311.49
GY$20,944.44
List Price:  GY$29,323.05
You save:  GY$8,378.61
ISK kr14,022.59
List Price:  ISK kr19,632.19
You save:  ISK kr5,609.60
DH1,011.24
List Price:  DH1,415.78
You save:  DH404.53
L1,769.74
List Price:  L2,477.71
You save:  L707.96
ден5,744.06
List Price:  ден8,041.92
You save:  ден2,297.85
MOP$807.26
List Price:  MOP$1,130.19
You save:  MOP$322.93
N$1,888.87
List Price:  N$2,644.49
You save:  N$755.62
C$3,684.35
List Price:  C$5,158.24
You save:  C$1,473.89
रु13,347.21
List Price:  रु18,686.63
You save:  रु5,339.41
S/376.08
List Price:  S/526.53
You save:  S/150.44
K386.44
List Price:  K541.04
You save:  K154.59
SAR375.02
List Price:  SAR525.05
You save:  SAR150.02
ZK2,652.95
List Price:  ZK3,714.24
You save:  ZK1,061.28
L464.20
List Price:  L649.90
You save:  L185.70
Kč2,348.23
List Price:  Kč3,287.62
You save:  Kč939.38
Ft36,571.12
List Price:  Ft51,201.04
You save:  Ft14,629.91
SEK kr1,091.69
List Price:  SEK kr1,528.41
You save:  SEK kr436.72
ARS$87,466.76
List Price:  ARS$122,456.97
You save:  ARS$34,990.20
Bs694.29
List Price:  Bs972.03
You save:  Bs277.74
COP$395,890.30
List Price:  COP$554,262.26
You save:  COP$158,371.95
₡50,869.89
List Price:  ₡71,219.89
You save:  ₡20,349.99
L2,472.19
List Price:  L3,461.17
You save:  L988.97
₲745,423.92
List Price:  ₲1,043,623.31
You save:  ₲298,199.38
$U3,863.50
List Price:  $U5,409.05
You save:  $U1,545.55
zł403.45
List Price:  zł564.85
You save:  zł161.39
Already have an account? Log In

Transcript

Hello, welcome to the 18th tutorial on the c++ programming series. In this part we're going to look at bitwise operators. So they was operator as the name suggests, so if you've done computer science programming before is we're affecting the bits of our variable values and so forth bit ik ones and zeros binary. And they the lowest level in computers because everything eventually just goes down to one. And they all have this is what you're using computers and whatnot. And microwave within the electronics is all built on top of ones and zeros on top of several of the layers, which we would generally interact with, but their ROI, then the need may arise to interact with the bit itself.

So let's go ahead and open up our project to show you the different bitwise operators. To truly get grasp of binary and bitwise. You really need to look into that two's complement. And cetera and the general binary a quick Google search and a general read for half an hour an hour will give you a good overview of what it's all about this tutorial is to show you how to actually use it within c++. So let's get rid of this second. And the first one we're gonna look at is the AND operator which uses the ampersand.

Next one is the OR operator, which is the vertical line, then our vertical lines code. But the next one, we're going to use the exclusive OR operator, which uses this upside down triangle or something called a carrot. Our thing and we're going to use the tilde I believe is called a tilde, which is the NOT operator is basically a unary compliment. It's a bit inversion and is tilde going to use the chef The bits to the left to the left, like the less than less than operator, sort of what we're using to try and see him, but it actually usage in here in this instance will be different from when we look at a ship it's to the right. And as you guessed it's to the right right. So let's just do a C out STD column and line and in here we are simply going to put five and free data in brackets now run this bad boy and we get a result of one and generally on the outside if not aware of binary you might think of it with five and free wine Michael a somehow because maybe I didn't cover everything.

And that's just quitted, show you what it's all about. Like I said, generally if you're doing this, I recommend you look up into computer science and then a bit about binary. But here's a quick overview. So we're just going to be using four binary digits for the purpose of this little simple example. So 0000 is zero. And the first digit we're starting to write represents the value one, then the next one represents the value two, therefore represents the value for you can get an excellent representative value eight, and so it says 1248 1632 64 and 48, so forth, and to build a number below five.

What you do is you look at it like this and from the left, you look okay, the first one represents eight because eight go into the value five knows that you put zero, does four go into the value five. Yes, there you go. to number one if you will want to zero on Raw source or like Boolean, so what is remaining is just one does to go into our no says zero. does one go into one? Yes, it does. And now we've made our num number five in binary.

Let's do the same for free. So the eight go into one. No, we're not done for going to a no it not the to load one it does indeed, what we have left is what 2.21 does, indeed. So that's just sort of separate this. What we're going to do is the result of the SOP for the AND operator, it goes through all of these and compares each binary bit with each other. So what it does is list we can distinct from the left, zero and 04.

And both of them need to be one for the result to be one 10001 and zero only one of them don't. So it's 001. Only one of them one, which is 01 and one is one. So let's just go over this again. Eight times zero is 04 times zero is 02 times zero is zero was this, we got for the one section one time long, because this bit it's done. So the result of this is one, you can easily apply it if you have a large number or a different number.

That's a rough General, just the an operator will comment this as and get rid of this. And that is to show you the OR operator lock set. If you want more information, you can message us and we will help as much as possible, but did a quick Google search should suffice as well. Let's just do the OR operator. Comment this ad for a moment, run it when we got seven. So let's just show you how this worked.

This is similar to be quite a long tutorial for quite a short one but one of the things is, let's just center this up. And for the OR operator, it looks for you and checks are only one of them needs to be on at the bare minimum. So zero and zero, none of none of me the answer is 01 and 01 is on Okay, the top one, the 1011 and then we'll put the other 1111 of them is on put the other one. So we got zero there, we got four plus two plus one, which equals seven Hope you're sort of seeing the patterns in how it works now as the exclusive OR rid of this second. So let's get the upside down triangle charactering you run this, we got six an exclusive OR basically say for the result to Be on, only one of them can actually be on.

So we'll show you by using this example. So the first one is 00. And nothing is on. So it's 01 of the results. So it's one because at least on amin, only one of them can be on. There are one is one was one on one is zero because it's Exclusive OR only one of them can be on at any given time.

So it's zero plus four plus two plus zero, so four plus two, which equals six. So let's just copy and paste lists. That's true, NOT operator, please did not even there it is. The total should say so this is minus six. This is somebody gonna look into a little more basically, this is two's complement is make a little note in here. You can check it out and not close.

Not Check out more info on that complement, complement. And you will understand what this is going on about but this just basically inverts the bit so ones become zeros and zeros become ones. And obviously because using the sign bit at the end is a negative because we're using too comfortable again and a lot of that might just mean who the bully to you how you're going to just sit there and you might have just understood the same Amanda Kay no failover Let's hope so it's something that you're gonna want to research because I'm going to showing you the feature when people first are late to these operators. She wants a modulation is best if you do believe or just messages. So let's just show you the last two quickly. The big boys, I mean this shift bits, put it in brackets, we're going to do Five, no six, shift that a name specify how many times you want to shift it to the left, and this is pointing to the left of a note or shifting it to the left though, we are shifting the value six.

I'm going to shift this bit, two points to the left. So let's run this little valley 24. Let's show you how this got to the value of 24. Get rid of that is shift left, shift bits to left, SPT shifted to left and six I believe is 00110. Don't put an excellent zero at the end, simply because that's what we're going to be dealing with the What this does, and it goes through them and basically shifts each bit, one to the left. So, this remains a zero because this one goes there.

The one goes to where this one is a one, then that one goes to where the other one was a one, zero goes to there, and anything that pops in the void, you consume that zero as well. So this is called is how we this produces 24. So it's one to four. Pay for Oh, sorry, my bad, meant to be shifting it to places that won't place Okay, no, no, we can leave that. I was gonna say, first shift. And then we can put second shift VM is shifted in two places.

So we have 124. The last two are eight and 1616 plus eight is 24. Hence what is printed out 24. So let's just show you the final which is shifting into the right, I was going to show you shift in one place and run it should be like free. So let's just copy and paste this shift bit, right. Alright, let's get rid of this.

Get rid of the second guy also get rid of this. I worried that it shifts all the bits to the right to now instead what's best for the members we have one so we go 0011 and we know that if the value one then the value of cherries are two plus one equals free, so hence white it prints out free. That's it for this tutorial. This was quite a long tutorial compared to the other tutorials in this series. If you have any questions feel free to message us at support at Sumner systems coda UK. The email will be in the description you can comment on the videos directly message us on YouTube.

Wherever you feel comfortable with all the requirements or source code will also be in the description. In the next tutorial we'll be looking at the size or size of operator. And as usual, thanks for watching and I hope you have a nice day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.