A Complete Guide to Programming in C++ part 75

A Complete Guide to Programming in C++ part 75. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | SOLUTIONS if count 0 count 15 cout Invalid input Shifting by one bit position. n count 1 cout nThe bit pattern of x setw 2 count putbits x count cout nThe bit pattern of x setw 2 count putbits x count cout nRepeat y n cin yn while yn 0x20 y yn n while yn y return 0 -------------------------------------------------------------- Output the bit pattern of n only the 16 lower bits . void putbits unsigned int n int i for i 15 i 0 --i cout char n i 1 0 i-th bit if i 4 0 i 0 and after 4 bits cout one blank. Exercise 2 --------------------------------------------------------- Filter to encrypt data. Swap bits in bit positions 5 and 6 0 and 4 1 and 3 for all characters except control characters. Modules Call hide_t sourcefile destfile --------------------------------------------------------- 720 CHAPTER 3 I MANIPULATING BITS include iostream using namespace std int swapbits int ch int bitnrl int bitnr2 Prototype int main Encrypt data int c while c EOF if c 32 Control character c swapbits c 5 6 Swap bits c swapbits c 0 4 c swapbits c l 3 cout c return 0 ------------------------------------------------------------ The function swapbits swaps two bits within an integer. Arguments The integer and two bit positions. Returns The new value. ------------------------------------------------------------ int swapbits int x int bitnrl int bitnr2 int newx maskl mask2 To swap two bits in x. int msb 8 sizeof int - 1 Highest bit position if bitnrl 0 bitnrl msb bitnr2 0 bitnr2 msb return x Return if bit position is invalid maskl 1 bitnrl Shift 1 to position bitnrl mask2 1 bitnr2 Shift 1 to position bitnr2 newx x mask1 mask2 Delete both bits if x mask1 newx mask2 Swap bits. if x mask2 newx mask1 return newx chapter Templates Templates allow you to construct both functions and classes based on types that have not yet been templates are a powerful tool for automating program code generation. This chapter describes how to .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.