summaryrefslogtreecommitdiff
path: root/c,cc/bitwise.c
blob: c90bfbd1db40def4ac3e0bc32601b3bbf2d4346d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>


void
test1()
{
  int foo[4] = {147, 142, 207, 19};
  unsigned long result = 0;

  for( int i = 0; i < 4; i += 1 )
  {
    result = result<<8;  // 8 bit left
    result = foo[i]|result;
  }

  printf("%lx\n", result);
}

void
test2(void)
{
  int foo[4];
  unsigned long bar = 0x938ecf13;

  for( int i = 0; i < 4; i += 1 )
  {
    foo[i] = (bar>>i*8)&255;

    printf("%d\n", foo[i]);
  }
}

void
test3(void)
{
  int s = 12;
  unsigned long foo = 0xffffffff;

  foo = foo<<s;
  printf("%lx\n", foo);
}

int main(void)
{
  test1();
  test2();
  test3();

  return 0;
}