DSCP Precedence

274 views Asked by At

How can I use Java to obtain the Precedence part of a DiffServe Code Point (DSCP) integer? I expect it involves bit shifting, but for some reason I cannot seem to obtain the values I would have expected.

1

There are 1 answers

2
Malt On BEST ANSWER

Assuming I understood you correctly, just perform a 3 bit logical shift to the right:

dscp >>> 3

Like this:

for (int dscp = 0; dscp < 57; dscp++) {
  System.out.println("DSCP:" + dscp + " Precedence:" + (dscp >>> 3));
}

Output:

DSCP:0 Precedence:0
DSCP:1 Precedence:0
DSCP:2 Precedence:0
DSCP:3 Precedence:0
DSCP:4 Precedence:0
DSCP:5 Precedence:0
DSCP:6 Precedence:0
DSCP:7 Precedence:0
DSCP:8 Precedence:1
DSCP:9 Precedence:1
DSCP:10 Precedence:1
DSCP:11 Precedence:1
DSCP:12 Precedence:1
DSCP:13 Precedence:1
DSCP:14 Precedence:1
DSCP:15 Precedence:1
DSCP:16 Precedence:2
DSCP:17 Precedence:2
DSCP:18 Precedence:2
DSCP:19 Precedence:2
DSCP:20 Precedence:2
DSCP:21 Precedence:2
DSCP:22 Precedence:2
DSCP:23 Precedence:2
DSCP:24 Precedence:3
DSCP:25 Precedence:3
DSCP:26 Precedence:3
DSCP:27 Precedence:3
DSCP:28 Precedence:3
DSCP:29 Precedence:3
DSCP:30 Precedence:3
DSCP:31 Precedence:3
DSCP:32 Precedence:4
DSCP:33 Precedence:4
DSCP:34 Precedence:4
DSCP:35 Precedence:4
DSCP:36 Precedence:4
DSCP:37 Precedence:4
DSCP:38 Precedence:4
DSCP:39 Precedence:4
DSCP:40 Precedence:5
DSCP:41 Precedence:5
DSCP:42 Precedence:5
DSCP:43 Precedence:5
DSCP:44 Precedence:5
DSCP:45 Precedence:5
DSCP:46 Precedence:5
DSCP:47 Precedence:5
DSCP:48 Precedence:6
DSCP:49 Precedence:6
DSCP:50 Precedence:6
DSCP:51 Precedence:6
DSCP:52 Precedence:6
DSCP:53 Precedence:6
DSCP:54 Precedence:6
DSCP:55 Precedence:6
DSCP:56 Precedence:7