bitwise shift

I need a really simple example of a bit shift

either << or

>>

with

int y = 0;

as start point

that is a good link

this is easier than i thought

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

#include <stdio.h>

int main()
{
  int y = 1;

  y = y << 7;

  printf("\nThe amount of y shifted 7 from amount of 1 is %d\n", y);

  return 0;

}


hrmm if i want 127 from 128
i'll need a y -= 1; line after
y = y << 7;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#include <stdio.h>

int main()
{
  int y = 1;

  y = y << 7;
  y -= 1;

  printf("\nThe amount of y shifted 7 from amount of 1 with a subtraction of 1 is %d\n", y);

  return 0;

}


yippee

Last edited on
Topic archived. No new replies allowed.