tailieunhanh - Algorithms and Data Structures in C part 4
To test out the derivation for calculating the 2’s complement of a number derived in Section a program to calculate the negative of a number is shown in Code List . | 10 10 To test out the derivation for calculating the 2 s complement of a number derived in Section a program to calculate the negative of a number is shown in Code List . The output of the program is shown in Code List . Problem investigates the output of the program. Code List Testing the Binary Operators in C Code List Output of Program in Code List A program demonstrating one of the most important uses of the OR operator is shown in Code List . The output of the program is shown in Code List . Figure demonstrates the value of x for the program. The eight attributes are packed into one character. The character field can hold 256 28 combinations handling all combinations of each attribute taking on the value ON or OFF. This is the most common use of the OR operators. For a more detailed example consider the file operation command for opening a file. The file definitions are defined in by BORLAND C as shown in Table . Figure Packing Attributes into One Character Code List Bit Operators Code List Output of Program in Code List Table Fields for File Operations in C Source enum open_mode in 0x01 open for reading out 0x02 open for writing ate 0x04 seek to eof upon original open app 0x08 append mode all additions at eof trunc 0x10 truncate file if already exists nocreate 0x20 open fails if file doesn t exist noreplace 0x40 open fails if file already exists binary 0x80 binary not text file A program illustrating another use is shown in Code List . If the program executes correctly the output file is created with the string This is a test placed in it. The file is opened for writing with ios out and for truncation with ios trunc. The two modes are presented together to the ofstream constructor with the use of the or function. Code List Simple File I O Previous Table of Contents Next Copyright CRC Press LLC Algorithms and Data Structures in C by Alan Parker CRC Press CRC .
đang nạp các trang xem trước