hi ,
I need help , on how to apply XOR on 2 byte variables .
the smalest var should be padded with 0.
any suggestions? it is really urgent.
thx .
Randa
Printable View
hi ,
I need help , on how to apply XOR on 2 byte variables .
the smalest var should be padded with 0.
any suggestions? it is really urgent.
thx .
Randa
Convert two variable in to bit number and XOR. Nothing more that that.
JVM do the XOR operation for you. So what's your question here?Quote:
byte x = 12; // 0000 1100
byte y = 10; // 0000 1010
System.out.println(x ^ y); // 0000 0110
Hi,
thx, but am new to java.
how to convert to bit??
i have 2 byte variables, and one is smalest than the other , so it should be padded with 0.
regards
What do you mean convert to bit? Possible you wish to print the individual bits, but we need to know what it is you want to end up with and why.
Just studies is ok answer, could be several things.
You don't need to randa, java does it for you.
But else you could use String.toByteArray() (I think)
Hi,
Eranga, your code returns : operator ^ cannot be applied to java.lang.string.byte
so....
i have 2 byte[] var to XOR , the result should be returned as byte[]
i tried converting to string , to have a sequence of 1s and 0s
it didn't work.
rgrds
Please post the full text of the error message.
Also post your code.
Your descriptions don't say what the code does.
What is that? In java class names start with Uppercase letters.Quote:
java.lang.string.byte
i've tried eranga's peice of code.
it returned operator ^ cannot be applied to java.lang.String.byte
Code:/**
* This code is a discussion of an opinion in a technical form.
* There is no legitimate derivite use, and is known to be flawed.
* Reader assumes the risk, of any kind and nature, in any time and place,
* without burden of proof of jurisdition nor Snake Oil Certificate of Military Grade Encryption.
*/
import java.security.SecureRandom;
class QuestionDemo
{
private static byte[] BeuafordsBytes;//
// Dem darn demos, oh what a yo-yo!
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
BeaufordsBytes = random.generateSeed(2);
// xor operations here as directed by poster....
Byte FirstBite = new Byte(BeaufordsBytes [0]);//
Byte SecondBite = new Byte(BeaufordsBytes [2]);//
PhoneHomeMessage phm = new PhoneHomeMessage(FirstByte.toString());//
phm.addData(SecondByte.toString());//
Internet.releaseNewSoftware(phm);//
EasyMoney.rakeItIn();//
this is the piece of code am working on
.........
byte[] entete2=new byte[12];
System.arraycopy(entete,0,entete2,0,entete.length) ;
System.arraycopy(bb,0,entete2,8,4);
messagesize=12+HEdatalength+HEdatalength2+cipherRn d.length;
smessage=new byte[messagesize];
System.arraycopy(entete2,0,smessage,0,entete2.leng th);
System.arraycopy(HE1,0,smessage,entete2.length,HE1 .length);
System.arraycopy(HE2,0,smessage,(entete2.length+HE 1.length),HE2.length);
System.arraycopy(cipherRnd,0,smessage,(entete2.len gth+HE1.length+HE2.length),cipherRnd.length);
at this point,i have to call a function with 2 parameters similar to smessage.
the function should apply the XOr and returns a byte [] value
i'll work on the code u provided
thx
When you get error messages, copy and paste the FULL text here. DO NOT EDIT them.Quote:
operator ^ cannot be applied to java.lang.String.byte
Your piece of code doesn't show why the ^ operator doesn't work.
Where is the code that Eranga showed you? It does an XOR on two bytes. If the bytes are in an array change the example to:
Given: byte[] b1 and byte[] b2
byte xorB = b1[i] ^ b2[i];
Yes, please sen your code here to see. In my code segment there is no any issues. May be you are using in wrong way. Sen the full code to see.