OSDN Git Service

addid library source 20140221
[zither/ds-zither.git] / libms / shift8_updown_in.c
1
2
3
4
5
6 #include <stdio.h>
7
8
9 // 一つの32Bit整数に4つの8Bit整数を含めて取り出す
10 // int main(void)
11 // {
12 // int bar = 0;
13 // int ab = 0;
14 // int abc = 0;
15 // int abcd = 0;
16 //
17 // int a = 10;
18 // int b = 20;
19 // int c = 30;
20 // int d = 40;
21 //
22 //
23 // int mask_4 = 0xff000000;
24 // int mask_3 = 0x00ff0000;
25 // int mask_2 = 0x0000ff00;
26 // int mask_1 = 0x000000ff;
27 //
28 // ab = ((a << 8) + b);
29 // abc = ((ab << 8) + c);
30 // abcd = ((abc << 8) + d);
31 //
32 //
33 // printf("a = %d, b = %d, c = %d, d = %d, ab = %d, abc = %d, abcd = %d\n", a, b, c, d, ab, abc, abcd);
34 // printf("ax = %x, bx = %x, cx = %x, dx = %x, abx = %x, abcx = %x, abcdx = %x\n", a, b, c, d, ab, abc, abcd);
35 //
36 // bar = ((abcd & mask_4) >> 24);
37 // printf("mask4 %x: %d\n", bar, bar);
38 //
39 // bar = ((abcd & mask_3) >> 16);
40 // printf("mask3 %x: %d\n", bar, bar);
41 //
42 // bar = ((abcd & mask_2) >> 8);
43 // printf("mask2 %x: %d\n", bar, bar);
44 //
45 // bar = (abcd & mask_1);
46 // printf("mask1 %x: %d\n", bar, bar);
47 //
48 // return 0;
49 // }
50 //
51
52
53 int shift8_updown_in(int sh24, int sh16, int sh8, int sh0)
54 {
55
56 int ret = 0;
57 int sha = 0;
58 int shb = 0;
59
60 if(sh24 >= 255){ sh24 = 254; }
61 if(sh24 < 0){ sh24 = 0; }
62
63 if(sh16 >= 255){ sh16 = 254; }
64 if(sh16 < 0){ sh16 = 0; }
65
66 if(sh8 >= 255){ sh8 = 254; }
67 if(sh8 < 0){ sh8 = 0; }
68
69 if(sh0 >= 255){ sh0 = 254; }
70 if(sh0 < 0){ sh0 = 0; }
71
72
73 sha = ((sh24 << 8) + sh16);
74 shb = ((sha << 8) + sh8);
75 ret = ((shb << 8) + sh0);
76
77 return ret;
78
79
80
81
82
83
84
85
86
87