Bitwise Operators, C++ Streams, and Visual Basic 6.0 Fundamentals
Bitwise Operators in C++
Understanding Bit Fields
Bitwise operators are used for bit fields.
- ~: Supplement to 1 (Bitwise NOT)
- <<: Left Shift
- >>: Right Shift
- &: Bitwise AND (Compares 2 bits)
- ^: Bitwise XOR (Exclusive OR – Compares 2 bits)
- |: Bitwise OR (Inclusive OR)
Detailed Explanation of Bitwise Operators
~ (Bitwise NOT): Inverts each bit of the operand. 0s become 1s, and vice versa.
<< (Left Shift): Shifts the bits to the left. The least significant bit is lost, and the new bit is 0.
>> (Right Shift): Shifts the bits to the right. The most significant bit is lost. If this is a positive number, the new bit will be 0, and if it is a negative number, the new bit will be 1.
& (Bitwise AND): Compares two operands bit by bit and returns a value built from the result. The result bit is 1 if both corresponding bits in the operands are 1, otherwise it is 0.
^ (Bitwise XOR): Similar to &, except the result bit is 1 if the corresponding bits in the operands are different (one is 0 and the other is 1), otherwise it is 0.
| (Bitwise OR): The result bit is 1 if at least one of the corresponding bits in the operands is 1, otherwise it is 0.
Example Code
#include <iostream>short zero = 0, one = 1, two = 2;int main() {std::cout << ~0 << " == " << ~zero << std::endl;std::cout << ~1 << " == " << ~one << std::endl;std::cout << ~2 << " == " << ~two << std::endl;}
C++ Streams
What are Streams?
Flow (iostream): A stream of data flowing from a source to a destination.
Text Flow: A sequence of characters that can be converted 1-to-1, read as written.
Binary Flow: A sequence of binary bits designed to transfer information more quickly.
Standard Stream Objects
- cout: An object of class ostream connected to the standard output.
- cin: An object of class istream connected to the standard input.
- cerr: An object of class ostream connected to the standard error output (without buffering).
- clog: An object of class ostream connected to the standard error output (with buffering).
Visual Basic 6.0
Introduction to Visual Basic 6.0
Visual Basic 6.0 refers to the method used by the Graphical User Interface (GUI).
Visual: Refers to the method that uses the Graphical User Interface.
Basic: Stands for Beginner’s All-purpose Symbolic Instruction Code.
Main Steps to Run Visual Basic
- Create the interface.
- Set properties.
- Write the code.
Main Windows and IDE
Main Windows: Form Designer and Toolbar.
IDE (Integrated Development Environment): Comprises a menu bar, toolbar, toolbox, form designer, project explorer, and properties window.
Toolbars vs. Toolbox
Toolbars and Menus: Represent familiar commands that facilitate quick access to the most commonly used operations. Examples include standard, normal, and drawing toolbars.
Toolbox: Allows the creation of the graphical user interface on the form.
Toolbox Icons
- Ptr: Pointer
- Img: PictureBox (Image)
- Lbl: Label
- Txt: TextBox
- Fra: Frame
- Frm: Form (Application Design)
- Cmd: Command Button
- Opt: Option Button (Radio Button)
- Chk: CheckBox
- Cbo: ComboBox
- Lst: ListBox
- HS: Horizontal Scroll Bar
- VS: Vertical Scroll Bar
- Tim: Timer
- Grd: Grid
Form Designer, Project Explorer, and Form Position
- Form Designer: Allows the design of the application, the window on which to place objects or controls for the user interface.
- Project Explorer: Contains all the files that constitute the application or project.
- Form Position: Specifies the position of one or more forms in an application.
Properties Window
Each object has an associated set of properties. Use this window to view or specify the property values.
Code Window
This window appears when you double-click an object on the form. It is formed by two combo boxes: one for the object name and another for the object’s event.