[Virtual Presenter] Good morning everyone. Today, we will be looking at the basics of manipulating bits. We will discuss topics such as binary to decimal conversion, how to work with negative numbers, logical and bitwise operators, and shifting. Let's get started and dive into the world of bit manipulation!.
[Audio] We will be talking about Bits Manipulation in this slide. We'll begin by discussing Binary to Decimal Conversion and the representation of Negative Numbers in bits. Subsequently, we'll cover the basic data types used in C programming, as well as the Logical and Bitwise Operators available. We will then examine Shifting Operators before concluding with a challenge to test our understanding..
[Audio] Using the binary set of numbers 1010011, the conversion to decimal can be done by summing the powers of two corresponding to the set of ones. Starting at the rightmost bit as 2^0, the decimal equivalent of the binary number is 83 when increasing from left to right and adding up the powers of two..
[Audio] We can observe a table on this slide with a list of numbers that appear in pairs. From the right side, the first two numbers add up to 2^0, the next two numbers add up to 2^1 and so forth until the last two numbers, which add up to 2^6. This visualizes how binary numbers can be used to represent data..
[Audio] Negative numbers play a crucial role in binary computation. Each number is represented by a series of bits, the first bit - the most significant bit (MSB) - indicates if it is positive or negative. A negative number is denoted by 1, while a positive number is denoted by 0. This is mainly used for arithmetic and logical operations..
[Audio] We are examining Signed Integer values, a type of number which can be either positive or negative. The Most Significant Bit (MSB) is used to establish the sign of the number. A MSB of 0 would signify a positive number, while a MSB of 1 would signify a negative number. To demonstrate this, if we consider the four examples provided, 0000 0000 is a positive number with the value of 0, 1000 0000 is a negative number with the value of -128, 0111 1111 is a positive number with the value of 127 and 1111 1111 is a negative number with the value of -1..
[Audio] For signed integers, if the most significant bit - MSB - has a value of 1, it indicates the number is negative, and a MSB of 0 means that the number is positive. To answer the questions given, 0000 0000 is equal to 0, 1000 0000 is equal to -128, 0111 1111 is equal to 127, and 1111 1111 is equal to -1..
[Audio] We will now discuss signed integers. The Most Significant Bit (MSB) is designated to represent the sign of the number. If the MSB has a value of 1, the number is negative; if the MSB has a value of 0, the number is positive. With this in mind, we can determine that 0000 0000 is 0, and 1000 0000 is -127. But what does 0111 1111 and 1111 1111 signify?.
[Audio] Our presentation's ninth slide is on bits manipulation. We'll examine how to interpret signed integers, which can be either positive or negative. For 0000 0000, the most significant bit - MSB - is 0, meaning the number is positive: 0. 1000 0000 has an MSB of 1, so its number is negative: -128, or -1 times two to the seventh power. 0111 1111 has an MSB of 0, denoting the number is positive: 127, or 1 times two to the sixth power, plus 1 times two to the fifth power, plus 1 times two to the fourth power, plus 1 times two to the third power, plus 1 times two to the second power, plus 1 times two to the first power, plus 1 times two to the zeroth power. Lastly, with 1111 1111, the MSB is again 1, indicating the number is negative: -1..
[Audio] The Most Significant Bit (MSB) is utilized to identify if an integer is positive or negative. If the MSB is 0, the value is positive, and if it is 1, the value is negative. For instance, a binary number that is all zeros such as 0000 0000 has a positive value of zero. A binary number with the MSB equal to one such as 1000 0000 is negative and its value is -128, which is derived from -1 multiplied by 2 to the power of 7. Similarly, the binary number 0111 1111 is positive and its value is 127, which is derived from 1 multiplied by 2 to the power of 6, 5, 4, 3, 2, 1 and 0. Finally, the binary number 1111 1111 is negative and its value is -127, which is derived from -1 multiplied by 2 to the power of 7 and 1 multiplied by 2 to the power of 6, 5, 4, 3, 2, 1 and 0..
[Audio] Let's take a look at the number -5. How do we represent it in binary? We start by taking the absolute value of -5, which is 5. We then convert this to binary. In binary, 5 is 101. But how do we represent the sign of -5? That's where the two's complement comes in: we simply invert the bits and add one. So -5 in binary is 1111 1011..
[Audio] We are discussing how to represent negative numbers in binary, a process which is simple yet effective. To begin, we take the absolute value of the negative number and then calculate the two's complement of this absolute value. This allows us to represent a negative number in binary. Let's delve into the steps further..
[Audio] In order to represent negative numbers in binary, the absolute value of the number must be taken first. For example, the absolute value of -5 is 5, which would be 00000101 in binary. To turn this to a negative number, the 2's complement method can be used, which means adding 1 to the 1's complement, resulting in a binary representation of -5 being 11111011..
[Audio] We will be discussing how to represent negative numbers in binary. To start, we take the absolute value of the negative number, so the absolute value of -5 is 5. Then, to calculate the 2s complement, we take the 1s complement of the number, which in this example is 1010. Finally, we add 1 to the 1s complement to get the 2s complement..
[Audio] Taking the example of -5, first we take its absolute value, which is 5. Then, we calculate the 2's complement of this absolute value by taking the 1's complement of the absolute value plus 1, resulting in the 2's complement of 5. Finally, we verify the result to ensure its correctness..
[Audio] To represent negative numbers in binary, we need to take the absolute value of the number, in this case, -5. To calculate the two's complement of the absolute value, we start by finding the One's complement of it, which is the inverse of it's binary form. We then add one to the calculated One's complement, that gives us the two's complement. Lastly, we can verify the result by plugging it into the original equation..
Bits for basic C data type. Type char unsigned char signed char int unsigned int signed int short int unsigned short int signed short int long int unsigned long int signed long int Size in bits 8 8 32 32 32 16 16 16 32 32 32 Min-Max Range —128 to 127 O to 255 —128 to 127 —2,147,483,648 to 2,147,483,647 O to 4,294,967,295 Same as int —32,768 to 32,767 O to 65,535 Same as short int —2,147,483,648 to 2,147,483,647 O to 4,294,967,295 -2,147,483,648 to 2,147,483,647.
[Audio] We are focusing on five data types used in C language: long long int, unsigned long long int, float, double and size in bits. Each type has its own size in bits and min-max range. For example, long long int has 64 bits and a min-max range of -263 to 263 -1, while unsigned long long int has 64 bits and a min-max range of 0 to 4,294,967,295. Float has 32 bits and a min-max range of IE—37 to IE+37 with six digits of precision, and double has 64 bits and a min-max range of IE—37 to IE+37 with ten digits of precision..
CHALLENGE.
[Audio] We are discussing bitwise operators, which are used to work with binary data. The binary AND operator is represented by a & symbol and combines two bits into one. The binary OR operator, symbolized by |, will result in a 1 if either of the two input bits is a 1. The binary XOR operator, represented by a ^, will lead to a 1 if the two input bits differ. Lastly, the binary Ones Complement operator, denoted by a ~, will invert the output bit..
[Audio] The Left Shift Operator is indicated by "<<" and the Right Shift Operator is indicated by ">>". These operators are used to manipulate data bits by shifting them in different directions. With the Left Shift Operator, the data sequence is shifted to the left and with the Right Shift Operator, the data sequence is shifted to the right..
[Audio] Bits Manipulation is an important concept in coding that can help students understand the core fundamentals of programming, and these two functions are great starting points to practice this subject. I'd encourage each student to practice writing these functions in order to better understand the concepts. I hope this presentation was helpful. Thanks for listening. Have a great day..