Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* T7 zadatak 3 - Napisati funkciju koja omogućava očitavanje n-tog
- bita registra u procesoru. - getBit
- • Napisati funkciju koja omogućava “setovanje” ntog
- bita registra u procesoru na jedinicu. – setBit
- • Napisati funkciju koja omogućava postavljanje ntog
- bita registra u procesoru na 0. – clearBit
- • Napisati funkciju koja omogućava promenu (1->0 i
- 0->1) n-tog bita registra u procesoru. - flipBit
- • Napisati test program koji ilustruje upotrebu ovih
- funkcija.*/
- #include <stdio.h>
- void getBit(int a,int b);
- void setBit(int a,int b);
- void clearBit(int a,int b);
- void flipBit(int a,int b);
- int main(){
- int a,b,i;
- printf("Unesite A:");
- scanf("%d",&a);
- printf("Unesite Nti bit:");
- scanf("%d",&b);
- getBit(a,b);
- setBit(a,b);
- clearBit(a,b);
- flipBit(a,b);
- return 0;
- }
- void getBit(int a,int b){
- a >> b-1;
- if(a && 1){
- printf("\nNti bit je 1.\n");
- }else printf("\nNti bit je 0.\n");
- }
- void setBit(int a,int b){
- int c;
- c = 1;
- c <<= (b-1);
- a = a|c;
- printf("%d \n",a);
- }
- void clearBit(int a,int b){
- int c;
- c = 1;
- c <<= (b-1);
- c = ~(c);
- a &= c;
- printf("%d \n",a);
- }
- void flipBit(int a,int b){
- int c = a;
- if((c<<(b-1))&&1){
- c = 1;
- c <<= (b-1);
- c = ~(c);
- a &= c;
- printf("%d \n",a);
- }else{
- c = 1;
- c <<= (b-1);
- a = a|c;
- printf("%d \n",a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment