Sponsored Content
Full Discussion: Analysis in bitwise XOR
Top Forums UNIX for Beginners Questions & Answers Answers to Frequently Asked Questions FAQ Submission Queue Analysis in bitwise XOR Post 302608273 by Corona688 on Friday 16th of March 2012 06:11:07 PM
Old 03-16-2012
You are getting a number of things mixed up together and confused.

Quote:
In general, if the operands are in the form of n ^ (n+1) and also n is an even number, then the result is always 1.
xor can be considered a form of comparison, too. What bit is going to change when you add 1 to an even number? The last bit, of course, the 1 bit. This isn't so mysterious or strange.

Your perl examples don't work because they contain syntax errors, logic errors, and you typed them in MS Word, which destroys all code by inserting smart quotes. But perl does, to my surprise, do what you say:

Code:
perl -e "print 'asdf' ^ 'asdf';" | hexdump -C
00000000  00 00 00 00                                       |....|
00000004

 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

bitwise operators

can anybody write a program to divide a number by another number using bitwise operators (9 Replies)
Discussion started by: areef4u
9 Replies

2. 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

3. Shell Programming and Scripting

xor 2 values in ksh?

i have to xor two variables in ksh. how to do that? tia, DN2 (5 Replies)
Discussion started by: DukeNuke2
5 Replies

4. Shell Programming and Scripting

Bitwise negation

I am taking an online course on Unix scripting. The topic is Unix arithmetic operators and the lesson is Logical and bitwise operations. It is not clear how much storage space Unix uses to represent integers that are typed. Bitwise negation caused me to question how many bits are used to... (3 Replies)
Discussion started by: dLloydm
3 Replies

5. Programming

bitwise and if

Hi Suppose we have these code lines: #define _IN_USE 0x001 /* set when process slot is in use */ #define _EXITING 0x002 /* set when exit is expected */ #define _REFRESHING 0x004 ... 1 main () { 2 3 unsigned r_flags =_REFRESHING; 4 5 if (r_flag &... (3 Replies)
Discussion started by: Puntino
3 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. Emergency UNIX and Linux Support

bitwise and between two 32 bit binaries

Hello All, i have two 16 bit binaries that in two different variables, i want to perform a bitwise AND between the two and store the result in a different variable. can anyone throw some light on doing this in a bourne shell... eg var1= 1110101010101011 ... (8 Replies)
Discussion started by: venu
8 Replies

8. 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

9. 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
Flow filter in tc(8)						       Linux						      Flow filter in tc(8)

NAME
flow - flow based traffic control filter SYNOPSIS
Mapping mode: tc filter ... flow map key KEY [ OPS ] [ OPTIONS ] Hashing mode: tc filter ... flow hash keys KEY_LIST [ perturb secs ] [ OPTIONS ] OPS := [ OPS ] OP OPTIONS := [ divisor NUM ] [ baseclass ID ] [ match EMATCH_TREE ] [ action ACTION_SPEC ] KEY_LIST := [ KEY_LIST ] KEY OP := { or | and | xor | rshift | addend } NUM ID := X:Y KEY := { src | dst | proto | proto-src | proto-dst | iif | priority | mark | nfct | nfct-src | nfct-dst | nfct-proto-src | nfct-proto-dst | rt-classid | sk-uid | sk-gid | vlan-tag | rxhash } DESCRIPTION
The flow classifier is meant to extend the SFQ hashing capabilities without hard-coding new hash functions. It also allows deterministic mappings of keys to classes. OPTIONS
action ACTION_SPEC Apply an action from the generic actions framework on matching packets. baseclass ID An offset for the resulting class ID. ID may be root, none or a hexadecimal class ID in the form [X:]Y. X must match qdisc's/class's major handle (if omitted, the correct value is chosen automatically). If the whole baseclass is omitted, Y defaults to 1. divisor NUM Number of buckets to use for sorting into. Keys are calculated modulo NUM. hash keys KEY-LIST Perform a jhash2 operation over the keys in KEY-LIST, the result (modulo the divisor if given) is taken as class ID, optionally off- set by the value of baseclass. It is possible to specify an interval (in seconds) after which jhash2's entropy source is recreated using the perturb parameter. map key KEY Packet data identified by KEY is translated into class IDs to push the packet into. The value may be mangled by OPS before using it for the mapping. They are applied in the order listed here: and NUM Perform bitwise AND operation with numeric value NUM. or NUM Perform bitwise OR operation with numeric value NUM. xor NUM Perform bitwise XOR operation with numeric value NUM. rshift NUM Shift the value of KEY to the right by NUM bits. addend NUM Add NUM to the value of KEY. For the or, and, xor and rshift operations, NUM is assumed to be an unsigned, 32bit integer value. For the addend operation, NUM may be much more complex: It may be prefixed by a minus ('-') sign to cause subtraction instead of addition and for keys of src, dst, nfct-src and nfct-dst it may be given in IP address notation. See below for an illustrating example. match EMATCH_TREE Match packets using the extended match infrastructure. See tc-ematch(8) for a detailed description of the allowed syntax in EMATCH_TREE. KEYS
In mapping mode, a single key is used (after optional permutation) to build a class ID. The resulting ID is deducible in most cases. In hashing more, a number of keys may be specified which are then hashed and the output used as class ID. This ID is not deducible in before- hand, and may even change over time for a given flow if a perturb interval has been given. The range of class IDs can be limited by the divisor option, which is used for a modulus. src, dst Use source or destination address as key. In case of IPv4 and TIPC, this is the actual address value. For IPv6, the 128bit address is folded into a 32bit value by XOR'ing the four 32bit words. In all other cases, the kernel-internal socket address is used (after folding into 32bits on 64bit systems). proto Use the layer four protocol number as key. proto-src Use the layer four source port as key. If not available, the kernel-internal socket address is used instead. proto-dst Use the layer four destination port as key. If not available, the associated kernel-internal dst_entry address is used after XOR'ing with the packet's layer three protocol number. iif Use the incoming interface index as key. priority Use the packet's priority as key. Usually this is the IP header's DSCP/ECN value. mark Use the netfilter fwmark as key. nfct Use the associated conntrack entry address as key. nfct-src, nfct-dst, nfct-proto-src, nfct-proto-dst These are conntrack-aware variants of src, dst, proto-src and proto-dst. In case of NAT, these are basically the packet header's values before NAT was applied. rt-classid Use the packet's destination routing table entry's realm as key. sk-uid sk-gid For locally generated packets, use the user or group ID the originating socket belongs to as key. vlan-tag Use the packet's vlan ID as key. rxhash Use the flow hash as key. EXAMPLES
Classic SFQ hash: tc filter add ... flow hash keys src,dst,proto,proto-src,proto-dst divisor 1024 Classic SFQ hash, but using information from conntrack to work properly in combination with NAT: tc filter add ... flow hash keys nfct-src,nfct-dst,proto,nfct-proto-src,nfct-proto-dst divisor 1024 Map destination IPs of 192.168.0.0/24 to classids 1-256: tc filter add ... flow map key dst addend -192.168.0.0 divisor 256 Alternative to the above: tc filter add ... flow map key dst and 0xff The same, but in reverse order: tc filter add ... flow map key dst and 0xff xor 0xff SEE ALSO
tc(8), tc-ematch(8), tc-sfq(8) iproute2 20 Oct 2015 Flow filter in tc(8)
All times are GMT -4. The time now is 04:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy