Skip to main content

Posts

Showing posts with the label Number System

Fibonacci Series, Prime Fibonacci Numbers

#include<stdio.h> #include<conio.h> void fibonacci ( int ); void primefibo ( int ); void main() { int n; printf("\n No. of Terms?:: "); scanf("%d",&n); fibonacci(n); printf("\n"); primefibo(n); } // Function for displaying Fibonacci Series void fibonacci(int n) { int i=2,t0=0,t1=1,tn=1; printf("\n SERIES :: "); printf("%d ",t0); while(i<n) { printf("%d ",tn); tn=t0+t1; t0=t1; t1=tn; i++; } printf("%d",tn); } // Function for displaying Prime Numbers from Fibonacci Series void primefibo ( int n ) { int i=2,t0=0,t1=1,tn=1; printf("\n Prime No. in SERIES :: "); while(i<n) { if(isprime(tn)) printf("%d ",tn); tn=t0+t1; t0=t1; t1=tn; i++; } if(isprime(tn)) printf("%d",tn); } // Function to check a number whether it is Prime or not int isprime( int n) { int i; if(i<=1) return 0; for(i=2;i<...

2's Complement of 2Byte Number

This program will work out the 2's Complement of a 2 Byte Number. As Microprocessor can perform 8 bits at a time in Accumulator, so we follow the foloowing Algo Fetch the 2 Byte Number in a Register Pair Bring Least Significant Byte of the Number from last Register into A (Accumulator) Make Complement of A and add 1 Store back the Updated LSByte into its source Register Bring MSByte of the Number from another Register into A Make Complement of A and add 1 if carry was genetrated at the time of LSByte opeartion Store back the Updated MSByte into its source Register Store the Result to a Memory location Suppose, Argument Number is stored in Location 1000H and 1001H Memory Location and store the value in 2000H and 2001H Memory Locations. Memory Location Hex Code Label Mnemonics Comment 3050 3051 3052 2A 00 10 START: LHLD 1000H ;Load the HL Register Pair with the content of Memory Location 1000H and 1001H 3053 7D MOV A, L ;Move the Content of L to A ( Accumulator ) 3054 2F...

Binary and Gray Code Interchange

V can convert ny Binary Number in2 its Gray Code @ nytime.V dn't need 2 start 4m 0. Da algo is: Binary to Gray Code Start 4m MSB (Left side of the Number) g(MSB)=b(MSB) g(ith bit)=b(ith bit) XOR b(i+1 th bit) As an Example: Binary= 1 0 0 0 1 1 0 |\|\|\|\|\|\| Gray = 1 1 0 0 1 0 1 Gray Code to Binary Start from MSB b(MSB)=g(MSB) b(ith bit)=g(ith bit) if the number of 1's preceding g(ith bit) is Even else b(ith bit)=NOT of g(ith bit) As an Example: Gray 1 1 0 0 1 0 1 Binary 1 0 0 0 1 1 0 Comments MSB Prec 1 is odd Prec 1 is Even Prec 1 is Even Prec 1 is Even Prec 1 is odd Prec 1 is Odd Here is a Conversion Program:: // Header Files Inclusion #include<stdio.h> #include<conio.h> #include<string.h> // User defined Functions Prototype List void printcenter(char *s,int c); // Function to print text in Center of Screen void printtabbed(char *s,int t,int c); // Function to print text with preceding space from the ...