mirror of
https://github.com/zach-sb/SENG2250_Assignment3.git
synced 2025-11-09 07:07:36 +11:00
giveuponkhan
This commit is contained in:
parent
4a8846dfe9
commit
a0ee0db03b
47
Q2Tools.java
47
Q2Tools.java
@ -30,41 +30,32 @@ public class Q2Tools {
|
|||||||
{
|
{
|
||||||
String bInBinary = Integer.toBinaryString(B);
|
String bInBinary = Integer.toBinaryString(B);
|
||||||
|
|
||||||
int test = 0;
|
double test = 1;
|
||||||
|
|
||||||
System.out.println(bInBinary);
|
|
||||||
|
|
||||||
int k = 0;
|
|
||||||
for(int i = bInBinary.length()-1; i >= 0; i--)
|
|
||||||
{
|
{
|
||||||
|
int k = 0;
|
||||||
|
//Loop through the Binary String, starting from the right
|
||||||
|
for(int i = bInBinary.length()-1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
|
||||||
if(bInBinary.charAt(i)=='1')
|
if(bInBinary.charAt(i)=='1')
|
||||||
{
|
{
|
||||||
double temp = Math.pow(2, k);
|
System.out.println("Loop: "+k);
|
||||||
System.out.println(2+"^"+k+"="+temp);
|
double step1 = Math.pow(2, k);
|
||||||
test += temp;
|
System.out.println("STEP1: "+step1);
|
||||||
|
|
||||||
|
double step2 = Math.pow(A, step1)%C;
|
||||||
|
System.out.println("STEP2: "+step2);
|
||||||
|
test= test*step2;
|
||||||
|
|
||||||
|
}
|
||||||
|
k++;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
System.out.println(0+"^"+k+"=0");
|
|
||||||
}
|
|
||||||
k++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
System.out.println(test);
|
System.out.println(test);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
System.out.println(Math.pow(5, 64)%19);
|
||||||
* Simply wrapper for Integer.toBinaryString
|
|
||||||
* @param number integer to be converted to binary
|
|
||||||
* @return binary of number as an Biginteger
|
|
||||||
*/
|
|
||||||
public BigInteger convertToBinaryBigInt(int number)
|
|
||||||
{
|
|
||||||
//Take input number, convert to binary string
|
|
||||||
String binaryString = Integer.toBinaryString(number);
|
|
||||||
BigInteger bigBinary = new BigInteger(binaryString);
|
|
||||||
return bigBinary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user