xor 2 values in ksh?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting xor 2 values in ksh?
# 1  
Old 11-08-2006
xor 2 values in ksh?

i have to xor two variables in ksh. how to do that?

tia,
DN2
# 2  
Old 11-08-2006
It's easier done with Perl:

Code:
perl -le 'print (16 ^ 5)'
21

perl -le 'print (21 ^ 5)'
16

# 3  
Old 11-08-2006
perl is no option.... its not on all systems Smilie
# 4  
Old 11-08-2006
A possible solution:
Code:
a=15
b=10
a_xor_b=$(perl -e "print $a^$b")     <- gives 5


Jean-Pierre.
# 5  
Old 11-08-2006
Quote:
Originally Posted by DukeNuke2
perl is no option.... its not on all systems Smilie
Sorry, my bad. This can be done with KSH using built in operations (I haven't really had a need for this to date).

Code:
print $(( 16 ^ 5 ))
21

print $(( 21 ^ 5 ))
16

# 6  
Old 11-08-2006
Quote:
Originally Posted by tmarikle
Sorry, my bad. This can be done with KSH using built in operations (I haven't really had a need for this to date).

Code:
print $(( 16 ^ 5 ))
21

print $(( 21 ^ 5 ))
16

this works... thank you so much!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

XOR two strings

hi, i am new to shell programming, can u please tell me how to perform XOr operation of two strings. i tried to do xor using ^symbol but this doesnt work. help me with this Thanks (12 Replies)
Discussion started by: anil_uvce
12 Replies

2. FAQ Submission Queue

Analysis in bitwise XOR

The purpose of this article is revealing the unrevealed parts of the bitwise XOR. As we aware, the truth table for the XOR operator is : A B A^B 0 0 0 0 1 1 1 0 1 1 1 0 For example , 1^2 will be calculated as given below: First the operands... (1 Reply)
Discussion started by: pandeesh
1 Replies

3. UNIX for Dummies Questions & Answers

XOR between strings

I am aware of truth table for XOR between binary values . Out of curious in would like to know how XOR works between 2 strings which contain alphabets . For example A ^ B How it works internally? Please help me to understand this Thanks (1 Reply)
Discussion started by: pandeesh
1 Replies

4. Shell Programming and Scripting

ksh to compare alphanumeric values from 2 files

Hi there, I want to compare 2nd column which are alphanumeric values from each of the 2 files i.e.,lspv_pre.out and lspv_post.out , if found echo some message. lspv_pre.out hdisk0 00c39eaa451144dd rootvg active hdisk1 00c39eaa45223322 ... (3 Replies)
Discussion started by: mbak
3 Replies

5. Shell Programming and Scripting

passing values to function in Ksh

Hi, I'm trying to work on the script given below #!/bin/ksh -x pfile() { echo "$1" } touch smp19 echo "Hi" > smp19 result=$(pfile $smp19) echo $result As highlighted , when i pass $smp19 as parameter ,it does not display the output.However when i try giving "Hi" instead... (2 Replies)
Discussion started by: Sheema
2 Replies

6. Programming

A trivial XOR doubt in a program

Hi, I am trying to reverse a string using the following program utilizing the Exclusive OR bit operation: int main() { char str = "Quraish"; char *p = str, temp; char *q = str + strlen(str) - 1; while ( p != q ) { if (*p != *q) { *p ^= *q; *q ^= *p; *p ^= *q;... (1 Reply)
Discussion started by: royalibrahim
1 Replies

7. Shell Programming and Scripting

read values from ps -ef into variables in ksh?

Hi, I want to get the first two items returned by ps -ef into two variables? Can anyone please help Thanks (8 Replies)
Discussion started by: JamesByars
8 Replies

8. Programming

resetting counter using bitwise XOR

Hi ! How to reset a variable to 0 after a reset value, say 10 using bitwise XOR. For example, int cnt=0; if(cnt<10) cnt++; else cnt = 0; How can we achieve this by using XOR only. thanks, (1 Reply)
Discussion started by: mrgubbala
1 Replies

9. Shell Programming and Scripting

comparing two decimal values in KSH

Hi Gurus, I wrote a small KSH script, in that i am comparing two variables like this curr_time = date +%h.%m set_time=23.55 If ]; then zip the file fi The above script is croned to run evey 5(3,8,.......,58) minutes, but it is zipping at 23.03 hours. My intention is at 23.58 .what... (4 Replies)
Discussion started by: nandinisagar
4 Replies
Login or Register to Ask a Question