tailieunhanh - c for engineers and scientists introduction to programming with ansi c phần 9

Trên một mức độ cơ bản, chuỗi chỉ đơn giản là mảng ký tự có thể được thao tác bằng cách sử dụng các kỹ thuật chế biến tiêu chuẩn yếu tố phần tử mảng. Trên một mức độ cao hơn, chuỗi chức năng thư viện có sẵn để điều trị chuỗi như những thực thể hoàn chỉnh. Chương này tìm hiểu các đầu vào, | The AND Operator 519 Program 13-2 uses this masking property to convert lowercase letters in ai word into their its uppercase form assuming the letters are stored using the ASCII code. The algorithm for converting letters is based on the fact that the binary codes for lowercase and uppercase letters in ASCII are the same except for bit 6 which is 1 for lowercase letters and 0 for uppercase letters. For example the binary code for the letter a is 01100001 hex 61 while the binary code for the letter A is 01000001 hex 41 . Similarly the binary code for the letter z is 01111010 hex 7A while the binary code for the letter z is 01011010 hex 5A I See Appendix F for the hexadecimal values of the uppercase and lowercase letters. Thus a lowercase letter can be converted into its uppercase form by forcing the sixth bit to zero. This is accomplished in Program 13-2 by masking the letter s code with the binary value 11011111 which has the hexadecimal value DF. Program 13-2 include main i i char word 81 enough storage for a complete line. void upper char function prototype printf Enter a string of both upper and lowercase letters n gets word ị printf nThe string of letters just entered is n I puts word upper word printf nThis string in uppercase letters is n puts word void upper char word while word 0 word 0XDF A sample run using Program 13-2 follows Enter a string of both upper and lowercase letters abcdefgHIJKLMNOPqrstuvwxyz The string of letters just entered is abcdefgHIJKLMNOPqrstuvwxyz This string in uppercase letters is ABCDEFGHIJKLMNOPQRSTUVWXYZ 520 Chapter Thirteen Bit Operations Notice that the lowercase letters are converted to uppercase form while uppercase letters are unaltered. This is because bit 6 of all uppercase letters is zero to begin with so that forcing this bit to zero using the mask has no effect. Only when bit 6 is a one as it is for lowercase letters is the input character altered. The Inclusive OR Operator The inclusive OR operator I .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.