Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
You are viewing an older revision! See the latest version
Bitmanipulationen Grundlegend
Kopiere das Programm in den mbed-Simulator und ändere die globale Variable shift und kontrolliere die vier blauen Leds.
bit-shift.cpp
#include "mbed.h" DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); uint8_t pos = 0; uint8_t shift = 3; // change the value between 0 and 3 int main() { while (1) { pos = (1 << shift); // shift left printf("%d\n", pos); if(pos == 0b00001000) led4 = !led4; if(pos == 0b00000100) led3 = !led3; if(pos == 0b00000010) led2 = !led2; if(pos == 0b00000001) led1 = !led1; wait_ms(500); } }
Maskierung Baue die folgende Funktion in ein Programm ein.
<<code function>>
uint8_t maskAnd() {
uint8_t mask = 0x0f; 00001111b
uint8_t value = 0x55; 01010101b
return mask & value;
}
<</code>