P4E Lecture 10 - Low Level Bit Programming
P4E Lecture 10 - Low Level Bit Programming
University of the
Concepts – Bit operations
West of England Programming for Engineers
LESSON PLAN K. Emrith @
UWE2019
• Bit Manipulation
– Bit Manipulation Operators
– Compound Assignments
– Bit Masking
Binary to decimal conversion K. Emrith @
UWE2019
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
1 0 0 0 0 0 1 1
128+2+1 = 131
Binary to hexadecimal conversion K. Emrith @
UWE2019
8 4 2 1
1 1 1 0
14 in decimal => E
[0 1 2 3 4 5 6 7 8 9 A B C D E
F]
Declaring Binary or Hex values K. Emrith @
UWE2019
X = 15; //decimal
X = 0xF; //Hex
X = 0b1111; //binary
~ 1001 0110
/* Infinitely shift a variable with one bit set back and forth, and write it to the LED PIO. Software
loop provides delay element. See if you can understand it, it will be great revision!*/
while (1){
if (led & 0x9){ dir = (dir ^ 0x1);}
if (dir){ led = led >> 1;}
else{ led = led << 1; }
IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, led);
i = 0;
while (i<200000)
i++;
} //end while
return 0;
}