Question: Using the program Logisim Either make two circuits connected together (Grey code to BCD connected with BCD to 7-LED) or one circuit (Grey code to

Using the program Logisim

Either make two circuits connected together (Grey code to BCD connected with BCD to 7-LED) or one circuit (Grey code to Seven Segment LED) Inputs are Grey code for 0-9. 10-15 should output 1111 and the DP LED should be set

Make sure you are working with the correct inputs and your circuit is producing the correct output

To the end (and because I was bored last night) I have created a small Java program that will convert between binary and Grey code

You do not have to black box the circuits or use advance features but your circuit does have to be neat and tidy, clearly labeled and well thought out

(program code provided)

// Java program for converting between Binary and grey // it will display tables (0-15) Binary to Grey and Grey to Binary // or // if given two arguments: // first "binary" or "grey" // second: string of zero and ones // // it will take then convert number to Grey code or Binary // // // usage: java conversion [ BINARY | GREY ]"); // // e.g. java conversion BINARY 0011 "); // returns 0010 // // e.g. java conversion // returns two tables Binary to Grey and Grey to Binary // // // import java.io.*;

class conversion { // function to xor static char xor_c(char x, char y) { return (x == y)? '0': '1'; } // function to flip static char flip(char c) { return (c == '0')? '1': '0'; } // convert binary to grey static String binary2grey(String binary) { String grey = ""; // MSB of grey code is same grey += binary.charAt(0); // Compute remaining, next bit is comuted by // XOR previous and current in Binary for (int i = 1; i < binary.length(); i++) { // XOR previous bit with current bit grey += xor_c(binary.charAt(i - 1), binary.charAt(i)); } return grey; }

// convert grey to binary static String grey2binary(String grey) { String binary = ""; // MSB of binary is same grey binary += grey.charAt(0); // Compute remaining bits for (int i = 1; i < grey.length(); i++) { // If current bit is 0, // concatenate previous bit if (grey.charAt(i) == '0') binary += binary.charAt(i - 1); // Else, concatenate invert of previous bit else binary += flip(binary.charAt(i - 1)); } return binary; }

// array for printing out Hexidecimal for 0-F static char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'b', 'C', 'd', 'E', 'F'}; // B2G : Binary to Grey or G2B : Grey to Binary static enum convert{B2G, G2B;}

// printout table of 0-15 for Binary to Grey and Grey to Binary static void display(convert way) { conversion map = new conversion(); int i=0; if(way==convert.B2G) System.out.println(" #\tBinary\tGrey"); else System.out.println(" #\tGrey\tBinary"); for(char w ='0'; w < '2'; w++){ for(char x ='0'; x < '2'; x++){ for(char y ='0'; y < '2'; y++){ for(char z ='0'; z < '2'; z++, i++){ String tmp = new String(""+w+x+y+z+""); if(way==convert.B2G) System.out.println(" "+ i +"\t"+tmp+"\t"+map.binary2grey(tmp)+"\t"+hex[i]); else System.out.println(" "+ i +"\t"+tmp+"\t"+map.grey2binary(tmp)+"\t"+hex[i]); } // z } // y } // x } // w }

// convert a binary String to integer static int bin2dec(String binary){ int num = 0; for (int i = binary.length()-1; i>=0; i--) { int index = binary.length()-1-i; num += ('1'==binary.charAt(i)? Math.pow(2,index) : 0); } return num; }

public static void main(String args[]) throws IOException { if ( args.length==2) { String binary; System.out.println(" "); if(args[0].toUpperCase().equals("BINARY")){ binary = args[1]; System.out.println(" Binary to Grey \tDec/Hex"); System.out.printf(" %-9s %-10s\t",args[1],conversion.grey2binary(args[1])); } else { binary = conversion.grey2binary(args[1]); System.out.println(" Grey to Binary \tDec/Hex"); System.out.printf(" %-7s %-10s\t",args[1],conversion.grey2binary(args[1])); } if(bin2dec(binary)>15) System.out.println(bin2dec(binary)+" "); else System.out.println(hex[bin2dec(binary)]+" "); } else if ( args.length == 0 ) { System.out.print(" "); display(convert.B2G); System.out.print(" "); display(convert.G2B); } else { System.out.println("Binary/Grey conversion program"); System.out.println("usage: java conversion [ BINARY | GREY ]"); System.out.println("e.g. java conversion BINARY 0011 "); System.out.println("e.g. returns \t 0010 "); System.out.println(" "); System.out.println("e.g. java conversion "); System.out.println("e.g. returns a two tables Bianry to Grey and Grey to Binary "); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!