このコードは、サイズが(s[i].length()
)の配列の最後のビットを出力しているだけです。文字列がHELLO WORLD!
であると仮定した場合、その文字列の1ビットだけ回転したまま、!
のバイナリ値が残っています。配列に格納された8ビットのバイナリを左循環シフトする方法
int power = 0,temp;
int[] a= new int[1000];
int[] m=new int[1000];
int[] dt=new int[1000];
int[] bindt=new int[100];
int[] ds=new int[1000];
int[] di=new int[50];
int[] cov=new int[100];
int arr[]=new int[10];
int var;
String d = null;
String e= null;
int bin[]=new int[8];
int bink[]=new int[8];
JFileChooser chooser = new JFileChooser(); // Browse File
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
fileName = file.getPath();
String fn= file.getName();
System.out.println("File name is :"+fn);
FileReader fileReader = new FileReader(fileName);
BufferedReader br = new BufferedReader(fileReader);
while ((line = br.readLine()) != null)
{
System.out.println(line);
l = line.length();
System.out.println("length is " + l);
System.out.print("Plain Text={");
while ((br.readLine() != null) || (i <= l)) //computing plain text
{
s[i] = line;
i++;
}
//counting no of vowels,consonants,special symbols and spaces
for (i = 0; i < s[i].length(); i++) {
char ch = line.charAt(i);
if (ch=='e'||ch=='a'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
vowels++;
else if (line.charAt(i)==' ')
spaces++;
else if (ch=='>'||ch=='+'||ch=='}'||ch=='/'||ch=='*'||ch=='!'||ch=='@'||ch=='#'||ch=='$'||ch=='%'||
ch=='^'||ch=='&'||ch=='('||ch==')'||ch=='"'||ch==':'||ch==';'||
ch=='{'||ch=='['||ch==']'||ch=='?'||ch==','||ch=='.'||ch=='<')
ss++;
else
consonants++;
ascii = (int) ch;
a[i] = ascii;
System.out.print(+a[i]+",");
}
System.out.print("}");
System.out.print("\n");
System.out.print("Static text={");
for (i = 0; i < s[i].length(); i++) {
m[i]=(254 - ((a[i]) - (14))); //Generating static text
System.out.print(+ m[i]+",");
}
System.out.print("}");
System.out.print("\n");
System.out.println("X=number of vowels = "+vowels);
System.out.println("W=number of consonants = "+consonants);
System.out.println("Z=number of special symbols = "+ss);
System.out.println("Y=number of spaces = "+spaces);
System.out.println("N=Total number of characters = "+l);
Denominator = ((l-consonants)+(l-vowels)+(l-spaces)+(l-ss));
System.out.println("Denominator is :"+Denominator);
System.out.print("Binary Value is: ");
j=7;
//loop for finding binary number
while(l!=0) // binary number computation
{
bin[j]=Math.abs(l%2);
l=l/2;
j=j-1;
}
for(j=0;j<8;j++)
System.out.print(bin[j]);
// loop for obtaining 1's complement
for(j=0;j<8;j++)
{
if(bin[j]==1)
bin[j]=0;
else
bin[j]=1;
}
System.out.print("\n");
System.out.println("Complemented value:")
d=Arrays.toString(bin).trim().replace(",","").replace("[","").replace("]","").replace(" ","").trim();
System.out.println(d);
System.out.print("Numerator: ");
Numerator = Integer.parseInt(d,2); //Computing k value
System.out.println(Numerator);
k=((Numerator)/(Denominator));
System.out.println("K =" +k);
System.out.print("Dynamic Text:{"); //Generating dynamic text
for (i = 0; i < s[i].length(); i++)
{
dt[i]=((m[i])+(k));
System.out.print(+ dt[i]+",");
}
z=7;
while(k!=0)
{
bink[z]=Math.abs(k%2);
k=k/2;
z=z-1;
}
System.out.println("}");
System.out.println("Binary Value of k is: ");
for(z=0;z<8;z++)
System.out.print(bink[z]);
}
System.out.println("ASCII Values of Dynamic Text is:");
for (int h = 0; h < s[i].length(); h++) //loop for computing binary value
{
System.out.print(" " + dt[h] + " = ");
int g=7;
while(dt[h]!=0) {
bindt[g]=(Math.abs((dt[h])%2));
dt[h]=(dt[h])/2;
g=g-1;
}
一覧:誰かが実際のコードがある
for (i = 0; i < s[i].length(); i++) { //loop for computing binary value System.out.print(" " + dt[i] + " = "); int g=7; while(dt[i]!=0) { bindt[g]=Math.abs((dt[i])%2); dt[i]=(dt[i])/2; g=g-1; } for(g=0;g<8;g++) System.out.print(bindt[g]); } } for(i=0;i<s[i].length();i++) //loop for circular shift on bits { var=bindt[0]; for(int index=0;index<8;index++) { di[index]=bindt[index+1]; if(index==7) di[index]=var; } } }
a[205]=10000111
a[202]=10010101
のような円形の左シフト出力した後仮定する
a[i]={202,205}
a[202]=11001010
とa[205]=11000011
があるべきhelp..pleaseすることができますアイテム} for(g=0;g<8;g++) System.out.print(bindt[g]); } } for(int h=0;h<s[i].length();h++) //loop for circular shift { for(int index=0;index<8;index++) { di[index]=bindt[index+1]; if(index==7) di[index]=bindt[0]; } }
System.out.println( "\ n循環シフト:"); (int index = 0; index < 8; index ++) System.out.print(di(0);}); [インデックス]); } } }
私はここでビットシフト演算子を見ることができません、そして、それはバイナリシフト演算を実行するはずのコードでは悪いです。 – zubergu
for条件索引付けのループ変数を使用して、 'i
シフト演算子 '<<' '<<<' '>>' '>>>' – ACV