Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 9945b88

Browse files
committed
Release + Updates
1 parent 62627a2 commit 9945b88

File tree

9 files changed

+208
-14
lines changed

9 files changed

+208
-14
lines changed

ComplementRange.class

2.41 KB
Binary file not shown.

ComplementRange.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import javax.swing.*;;
2+
public class ComplementRange {
3+
public static void main (String[] args){
4+
String explanation, explanation2, explanation3, explanation4, explanation5, explanation6;
5+
6+
explanation = "Ranges refer to the set of values that can be represented by a particular data type or number system.\nIn computer programming, ranges are often used to determine the valid input values for a variable or to define the limits of a computation.";
7+
explanation2 = "To Calculate The Range of a 2's Complement Representation we must to the following :";
8+
explanation3 = "Step 1 : Calculate 2 to the power of the number of bits you have. \n2^8 = 256";
9+
explanation4 = "Step 2 : Find the negative range by halving the answer. \n 256/2 = 128";
10+
explanation5 = "Step 3 : This means we have the range of: \n-128 to +128";
11+
explanation6 = "Step 4 : We need to take account the number 0 in our calculation, simply subtract 1 from the positive side.\n Our new answer is : -128 to +127";
12+
13+
JOptionPane.showMessageDialog(null, explanation, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
14+
JOptionPane.showMessageDialog(null, explanation2, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
15+
JOptionPane.showMessageDialog(null, explanation3, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
16+
JOptionPane.showMessageDialog(null, explanation4, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
17+
JOptionPane.showMessageDialog(null, explanation5, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
18+
JOptionPane.showMessageDialog(null, explanation6, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
19+
20+
while (true) {
21+
// Read decimal input from the user
22+
String input = JOptionPane.showInputDialog(null, "Enter The Number of Bits in the Representation :");
23+
24+
if (input == null || input.equalsIgnoreCase("q")) {
25+
JOptionPane.showMessageDialog(null, "Operation Cancelled");
26+
break;
27+
}
28+
29+
// Convert input string to integer
30+
int bits;
31+
try {
32+
bits = Integer.parseInt(input);
33+
} catch (NumberFormatException e) {
34+
JOptionPane.showMessageDialog(null, "Invalid input. Please enter an integer.");
35+
continue;
36+
}
37+
38+
int minValue = -(1 << (bits - 1)); // minimum value that can be represented
39+
int maxValue = (1 << (bits - 1)) - 1; // maximum value that can be represented
40+
41+
JOptionPane.showMessageDialog(null, "Range of values in " + bits + "-bit 2's complement: \nMinimum value: "+ minValue + "\nMaximum value: "+ maxValue);
42+
}
43+
}
44+
}
45+
46+
// Kayel Calleja
47+
48+
// << is a left shift operator shifting it by 1 in this case.

ComputingPresentation.jar

34.3 KB
Binary file not shown.

Group2Presentation.exe

34.3 KB
Binary file not shown.

NOTES.TXT

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,7 @@ try{
8787
if the decimal value is 1234, taking 1234 % 10 would result in a value of 4, which is the last digit.
8888

8989
// String Builder breaks down mulitple little strings e.g sb.append = group ,
90-
// sb.append = two. and compile them into one whole string acting as a buffer : String Result = sb.toString();
90+
// sb.append = two. and compile them into one whole string acting as a buffer : String Result = sb.toString();
91+
92+
93+
<< is a left shift operator shifting it by 1 in this case.

SignAndMagnitudeRange.class

2.24 KB
Binary file not shown.

SignAndMagnitudeRange.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import javax.swing.*;
2+
public class SignAndMagnitudeRange {
3+
public static void main (String[] args){
4+
String explanation, explanation2, explanation3, explanation4;
5+
6+
explanation = "Ranges refer to the set of values that can be represented by a particular data type or number system.\nIn computer programming, ranges are often used to determine the valid input values for a variable or to define the limits of a computation.";
7+
explanation2 = "To Calculate The Range of a Sign+Magnitude Representation we must to the following :";
8+
explanation3 = "Determine the number of bits used to represent the value. \n 4-bits";
9+
explanation4 = "Calculate the minimum and maximum values. \n+/- 4 2 1\n1 1 1 1 = -7\n0 1 1 1 = +7";
10+
11+
JOptionPane.showMessageDialog(null, explanation, "Sign+Magnitude Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
12+
JOptionPane.showMessageDialog(null, explanation2, "Sign+Magnitude Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
13+
JOptionPane.showMessageDialog(null, explanation3, "Sign+Magnitude Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
14+
JOptionPane.showMessageDialog(null, explanation4, "Sign+Magnitude Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
15+
while (true) {
16+
// Read decimal input from the user
17+
String input = JOptionPane.showInputDialog(null, "Enter The Number of Bits in the Representation :");
18+
19+
if (input == null || input.equalsIgnoreCase("q")) {
20+
JOptionPane.showMessageDialog(null, "Operation Cancelled");
21+
break;
22+
}
23+
24+
// Convert input string to integer
25+
int bits;
26+
try {
27+
bits = Integer.parseInt(input);
28+
} catch (NumberFormatException e) {
29+
JOptionPane.showMessageDialog(null, "Invalid input. Please enter an integer.");
30+
continue;
31+
}
32+
// Calculate the maximum and minimum values
33+
int maxValue = (int) Math.pow(2, bits - 1) - 1; // maximum value is 2^(bits - 1) - 1
34+
int minValue = -(int) Math.pow(2, bits - 1) + 1; // minimum value is -(2^(bits - 1)) + 1
35+
36+
JOptionPane.showMessageDialog(null, "Range of values in " + bits + "-bit Sign+Magnitude: \nMinimum value: "+ minValue + "\nMaximum value: "+ maxValue);
37+
}
38+
}
39+
}
40+
41+
// Kayel Calleja

main.class

2.57 KB
Binary file not shown.

main.java

Lines changed: 115 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,44 @@ public class main extends JFrame implements ActionListener{
88
private JButton button2;
99
private JButton button3;
1010
private JButton button4;
11+
private JButton button5;
12+
private JButton button6;
1113

1214
public main() {
1315
super("Main Menu");
1416

1517
// Create buttons
1618
button1 = new JButton("Unsigned Integers");
17-
button2 = new JButton("Sign+Magnitude");
19+
button2 = new JButton("Binary Coded Decimal");
1820
button3 = new JButton("2's Complement");
19-
button4 = new JButton("Binary Coded Decimal");
21+
button4 = new JButton("Sign+Magnitude");
22+
button5 = new JButton("2's Complement Ranges");
23+
button6 = new JButton("Sign+Magnitude Ranges");
2024

2125
// Set action listeners for buttons
2226
button1.addActionListener(this);
2327
button2.addActionListener(this);
2428
button3.addActionListener(this);
2529
button4.addActionListener(this);
26-
27-
// Add buttons to the frame
28-
getContentPane().setLayout(new FlowLayout());
29-
getContentPane().add(button1);
30-
getContentPane().add(button2);
31-
getContentPane().add(button3);
32-
getContentPane().add(button4);
30+
button5.addActionListener(this);
31+
button6.addActionListener(this);
3332

33+
// Create a nested panel with a margin of 10 pixels around the buttons
34+
JPanel buttonPanel = new JPanel(new GridLayout(3, 2, 10, 5));
35+
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 7, 5,7));
36+
buttonPanel.add(button1);
37+
buttonPanel.add(button2);
38+
buttonPanel.add(button3);
39+
buttonPanel.add(button4);
40+
buttonPanel.add(button5);
41+
buttonPanel.add(button6);
42+
43+
// Add the nested panel to the content pane
44+
getContentPane().setLayout(new BorderLayout());
45+
getContentPane().add(buttonPanel, BorderLayout.CENTER);
46+
3447
// Set frame properties
35-
setSize(330, 110);
48+
setSize(400, 140);
3649
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
3750
setLocationRelativeTo(null);
3851
}
@@ -41,11 +54,15 @@ public void actionPerformed(ActionEvent e) {
4154
if (e.getSource() == button1) {
4255
us();
4356
} else if (e.getSource() == button2) {
44-
sm();
57+
bcd();
4558
} else if (e.getSource() == button3) {
4659
c();
4760
} else if (e.getSource() == button4) {
48-
bcd();
61+
sm();
62+
} else if (e.getSource() == button5) {
63+
cr();
64+
} else if (e.getSource() == button6) {
65+
smr();
4966
}
5067
}
5168
private void sm(){
@@ -235,11 +252,96 @@ public static String decimalToBCD(int decimal){
235252
return bcd.toString();
236253
}
237254

255+
private void smr(){
256+
String explanation, explanation2, explanation3, explanation4;
257+
258+
explanation = "Ranges refer to the set of values that can be represented by a particular data type or number system.\nIn computer programming, ranges are often used to determine the valid input values for a variable or to define the limits of a computation.";
259+
explanation2 = "To Calculate The Range of a Sign+Magnitude Representation we must to the following :";
260+
explanation3 = "Determine the number of bits used to represent the value. \n 4-bits";
261+
explanation4 = "Calculate the minimum and maximum values. \n+/- 4 2 1\n1 1 1 1 = -7\n0 1 1 1 = +7";
262+
263+
JOptionPane.showMessageDialog(null, explanation, "Sign+Magnitude Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
264+
JOptionPane.showMessageDialog(null, explanation2, "Sign+Magnitude Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
265+
JOptionPane.showMessageDialog(null, explanation3, "Sign+Magnitude Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
266+
JOptionPane.showMessageDialog(null, explanation4, "Sign+Magnitude Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
267+
while (true) {
268+
// Read decimal input from the user
269+
String input = JOptionPane.showInputDialog(null, "Enter The Number of Bits in the Representation :");
270+
271+
if (input == null || input.equalsIgnoreCase("q")) {
272+
JOptionPane.showMessageDialog(null, "Operation Cancelled");
273+
break;
274+
}
275+
276+
// Convert input string to integer
277+
int bits;
278+
try {
279+
bits = Integer.parseInt(input);
280+
} catch (NumberFormatException e) {
281+
JOptionPane.showMessageDialog(null, "Invalid input. Please enter an integer.");
282+
continue;
283+
}
284+
// Calculate the maximum and minimum values
285+
int maxValue = (int) Math.pow(2, bits - 1) - 1; // maximum value is 2^(bits - 1) - 1
286+
int minValue = -(int) Math.pow(2, bits - 1) + 1; // minimum value is -(2^(bits - 1)) + 1
287+
288+
JOptionPane.showMessageDialog(null, "Range of values in " + bits + "-bit Sign+Magnitude: \nMinimum value: "+ minValue + "\nMaximum value: "+ maxValue);
289+
}
290+
}
291+
292+
private void cr(){
293+
String explanation, explanation2, explanation3, explanation4, explanation5, explanation6;
294+
295+
explanation = "Ranges refer to the set of values that can be represented by a particular data type or number system.\nIn computer programming, ranges are often used to determine the valid input values for a variable or to define the limits of a computation.";
296+
explanation2 = "To Calculate The Range of a 2's Complement Representation we must to the following :";
297+
explanation3 = "Step 1 : Calculate 2 to the power of the number of bits you have. \n2^8 = 256";
298+
explanation4 = "Step 2 : Find the negative range by halving the answer. \n 256/2 = 128";
299+
explanation5 = "Step 3 : This means we have the range of: \n-128 to +128";
300+
explanation6 = "Step 4 : We need to take account the number 0 in our calculation, simply subtract 1 from the positive side.\n Our new answer is : -128 to +127";
301+
302+
JOptionPane.showMessageDialog(null, explanation, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
303+
JOptionPane.showMessageDialog(null, explanation2, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
304+
JOptionPane.showMessageDialog(null, explanation3, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
305+
JOptionPane.showMessageDialog(null, explanation4, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
306+
JOptionPane.showMessageDialog(null, explanation5, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
307+
JOptionPane.showMessageDialog(null, explanation6, "2's Complement Ranges Explanation", JOptionPane.INFORMATION_MESSAGE);
308+
309+
while (true) {
310+
// Read decimal input from the user
311+
String input = JOptionPane.showInputDialog(null, "Enter The Number of Bits in the Representation :");
312+
313+
if (input == null || input.equalsIgnoreCase("q")) {
314+
JOptionPane.showMessageDialog(null, "Operation Cancelled");
315+
break;
316+
}
317+
318+
// Convert input string to integer
319+
int bits;
320+
try {
321+
bits = Integer.parseInt(input);
322+
} catch (NumberFormatException e) {
323+
JOptionPane.showMessageDialog(null, "Invalid input. Please enter an integer.");
324+
continue;
325+
}
326+
327+
int minValue = -(1 << (bits - 1)); // minimum value that can be represented
328+
int maxValue = (1 << (bits - 1)) - 1; // maximum value that can be represented
329+
330+
JOptionPane.showMessageDialog(null, "Range of values in " + bits + "-bit 2's complement: \nMinimum value: "+ minValue + "\nMaximum value: "+ maxValue);
331+
}
332+
}
238333
public static void main (String[] args){
239334
main menu = new main();
240335
menu.setVisible(true);
241336

242337
}
243338
}
244339

245-
// Kayel Calleja
340+
// Kayel Calleja
341+
342+
//sm = Sign and Magnitude
343+
//us = Unsigned
344+
//c = 2's Complement
345+
//bcd = Binary Coded Decimal
346+
//smr = Sign and Magnitude Ranges
347+
//cr = 2's Complement Ranges

0 commit comments

Comments
 (0)