Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <wiringPi.h>
- int binary(int num) {
- int mult = 1;
- int res = 0;
- while(num > 1) {
- int d = num % 2;
- res += d * mult;
- mult *= 10;
- num /= 2;
- }
- res += num * mult;
- return res;
- }
- int main (void)
- {
- int num;
- printf("Dame el numero para pasar a binario: ");
- scanf("%d", &num);
- wiringPiSetup();
- pinMode(0, OUTPUT);
- digitalWrite(0, LOW);
- pinMode(1, OUTPUT);
- digitalWrite(1, LOW);
- pinMode(2, OUTPUT);
- digitalWrite(2, LOW);
- pinMode(4, OUTPUT);
- digitalWrite(4, LOW);
- int res = binary(num);
- if(res % 10 == 1) {
- digitalWrite(4, HIGH);
- } else {
- digitalWrite(4, LOW);
- }
- res /= 10;
- if(res % 10 == 1) {
- digitalWrite(2, HIGH);
- } else {
- digitalWrite(2, LOW);
- }
- res /= 10;
- if(res % 10 == 1) {
- digitalWrite(1, HIGH);
- } else {
- digitalWrite(1, LOW);
- }
- res /= 10;
- if(res % 10 == 1) {
- digitalWrite(0, HIGH);
- } else {
- digitalWrite(0, LOW);
- }
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement