際際滷

際際滷Share a Scribd company logo
ANSI C
Language
Introduction
Lection 6
弌仂亟亠亢舒仆亳亠
 亳仂亳亠 仂仗亠舒亳亶
 丐亠仆舒仆亶 仂仗亠舒仂
 仂亞亳亠从亳亠 亳 弍亳仂于亠 仂仗亠舒亳亳
 亳仂于舒 舒亳仄亠亳从舒
23.05.2019 0:16 Introduction 2
亳仂亳亠 仂仗亠舒亳亶
亳 舒仄仂亠仆亳亳 于舒亢亠仆亳,
仂仗亠舒仂, 亳仄亠ム亳亠 弍仂仍亠亠 于仂从亳亶
仗亳仂亳亠, 弍亟 于亳仍亠仆 舒仆亠
仂仗亠舒仂仂于  仆亳亰从亳仄 仗亳仂亳亠仂仄.
3
亳仂亳亠 仂仗亠舒亳亶
4
亳仂亳亠 仂仗亠舒亳亶
舒亢亠仆亳亠
 舒 = b & 0xFF + 5
于亳仍磳 从舒从
 舒 = b & (0xFF + 5),
 于舒亢亠仆亳亠
 舒 + >> 1
于亳仍磳 从舒从
 (舒 + ) >> 1
5
丐亠仆舒仆亶 仂仗亠舒仂
亳仆舒从亳:
仍仂亞亳亠从仂亠 于舒亢亠仆亳亠 ? 于舒亢亠仆亳亠 1 : 于舒亢亠仆亳亠 2
1) 亳仍磳 仍仂亞亳亠从仂亠 于舒亢亠仆亳亠.
2) 仍亳 仍仂亞亳亠从仂亠 于舒亢亠仆亳亠 亳亳仆仆仂, 仂 于亳仍磳
亰仆舒亠仆亳亠 于舒亢亠仆亳亠 1, 于 仗仂亳于仆仂仄 仍舒亠  亰仆舒亠仆亳亠
于舒亢亠仆亳亠 2.
3) 亳仍亠仆仆仂亠 亰仆舒亠仆亳亠 于仂亰于舒舒亠.
仗亳仄亠:
min = (a < b) ? a : b;
6
丐亠仆舒仆亶 仂仗亠舒仂
7
int main()
{
unsigned char a, b, min, max;
a = 100; b = 200;
min = (a < b) ? a : b;
max = (a > b) ? a : b;
printf("Result: min = %d, max = %d", min, max);
return 0;
}
Result: min = 100, max = 200
仂亞亳亠从亳亠 亳 弍亳仂于亠 仂仗亠舒亳亳
8
Result: ????
int main()
{
unsigned char a, b, r1, r2, r3, r4;
a = 0xF0; b = 0x0F;
r1 = a & b;
r2 = a && b;
r3 = a | b;
r4 = a || b;
printf("Result: r1 = %x, r2 = %xn", r1, r2);
printf("Result: r3 = %x, r4 = %x", r3, r4);
return 0;
}
仂亞亳亠从亳亠 亳 弍亳仂于亠 仂仗亠舒亳亳
9
Result: r1 = 0, r2 = 1
Result: r3 = ff, r4 = 1
int main()
{
unsigned char a, b, r1, r2, r3, r4;
a = 0xF0; b = 0x0F;
r1 = a & b;
r2 = a && b;
r3 = a | b;
r4 = a || b;
printf("Result: r1 = %x, r2 = %xn", r1, r2);
printf("Result: r3 = %x, r4 = %x", r3, r4);
return 0;
}
亳仂于舒 舒亳仄亠亳从舒
10
Result: ????
int main()
{
unsigned char a, r1, r2;
a = 41;
r1 = a << 2;
r2 = a >> 2;
printf("Result: r1 = %dn", r1);
printf("Result: r2 = %d", r2);
return 0;
}
亳仂于舒 舒亳仄亠亳从舒
11
Result: r1 = 164
Result: r2 = 10
int main()
{
unsigned char a, r1, r2;
a = 41; // 0b 0010 1001 (41)
r1 = a << 2; // 0b 1010 0100 (164 = 41 * 4)
r2 = a >> 2; // 0b 0000 1010 (10 = 41 / 4)
printf("Result: r1 = %dn", r1);
printf("Result: r2 = %d", r2);
return 0;
}

More Related Content

C language lect_07_introduction

Editor's Notes

  1. https://ru.wikipedia.org/wiki/%D0%9E%D0%BF%D0%B5%D1%80%D0%B0%D1%82%D0%BE%D1%80%D1%8B_%D0%B2_C_%D0%B8_C%2B%2B