GlueGen: src/junit/com/jogamp/common/util/BitDemoData.java Source File

GlueGen v2.6.0 GlueGen, Native Binding Generator for Java™ (public API).

BitDemoData.java
Go to the documentation of this file.
1/**
2 * Copyright 2014 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.common.util;
30
31import java.nio.ByteBuffer;
32import java.util.Locale;
33
34 public class BitDemoData {
35 public static final long UNSIGNED_INT_MAX_VALUE = 0xffffffffL;
36
37 public static final String[] pyramid32bit_one = {
38 "00000000000000000000000000000001",
39 "00000000000000000000000000000010",
40 "00000000000000000000000000000100",
41 "00000000000000000000000000001000",
42 "00000000000000000000000000010000",
43 "00000000000000000000000000100000",
44 "00000000000000000000000001000000",
45 "00000000000000000000000010000000",
46 "00000000000000000000000100000000",
47 "00000000000000000000001000000000",
48 "00000000000000000000010000000000",
49 "00000000000000000000100000000000",
50 "00000000000000000001000000000000",
51 "00000000000000000010000000000000",
52 "00000000000000000100000000000000",
53 "00000000000000001000000000000000",
54 "00000000000000010000000000000000",
55 "00000000000000100000000000000000",
56 "00000000000001000000000000000000",
57 "00000000000010000000000000000000",
58 "00000000000100000000000000000000",
59 "00000000001000000000000000000000",
60 "00000000010000000000000000000000",
61 "00000000100000000000000000000000",
62 "00000001000000000000000000000000",
63 "00000010000000000000000000000000",
64 "00000100000000000000000000000000",
65 "00001000000000000000000000000000",
66 "00010000000000000000000000000000",
67 "00100000000000000000000000000000",
68 "01000000000000000000000000000000",
69 "10000000000000000000000000000000"
70 };
71
72 //
73 // MSB -> LSB over whole data
74 //
75 public static final byte[] testBytesMSB = new byte[] { (byte)0xde, (byte)0xaf, (byte)0xca, (byte)0xfe };
76 public static final int testIntMSB = 0xdeafcafe; // 11011110 10101111 11001010 11111110
77 public static final String[] testStringsMSB = new String[] { "11011110", "10101111", "11001010", "11111110" };
78 public static final String testStringMSB = testStringsMSB[0]+testStringsMSB[1]+testStringsMSB[2]+testStringsMSB[3];
79
80 //
81 // MSB -> LSB, reverse bit-order over each byte of testBytesLSB
82 //
83 public static final byte[] testBytesMSB_rev = new byte[] { (byte)0xfe, (byte)0xca, (byte)0xaf, (byte)0xde };
84 public static final int testIntMSB_rev = 0xfecaafde;
85 public static final String[] testStringsMSB_rev = new String[] { "11111110", "11001010", "10101111", "11011110" };
86 public static final String testStringMSB_rev = testStringsMSB_rev[0]+testStringsMSB_rev[1]+testStringsMSB_rev[2]+testStringsMSB_rev[3];
87
88 //
89 // LSB -> MSB over whole data
90 //
91 public static final byte[] testBytesLSB = new byte[] { (byte)0x7f, (byte)0x53, (byte)0xf5, (byte)0x7b };
92 public static final int testIntLSB = 0x7f53f57b;
93 public static final String[] testStringsLSB = new String[] { "01111111", "01010011", "11110101", "01111011" };
94 public static final String testStringLSB = testStringsLSB[0]+testStringsLSB[1]+testStringsLSB[2]+testStringsLSB[3];
95
96 //
97 // LSB -> MSB, reverse bit-order over each byte of testBytesMSB
98 //
99 public static final byte[] testBytesLSB_revByte = new byte[] { (byte)0x7b, (byte)0xf5, (byte)0x53, (byte)0x7f };
100 public static final int testIntLSB_revByte = 0x7bf5537f;
101 public static final String[] testStringsLSB_revByte = new String[] { "01111011", "11110101", "01010011", "01111111" };
102 public static final String testStringLSB_revByte = testStringsLSB_revByte[0]+testStringsLSB_revByte[1]+testStringsLSB_revByte[2]+testStringsLSB_revByte[3];
103
104 public static final void dumpData(final String prefix, final byte[] data, final int offset, final int len) {
105 for(int i=0; i<len; ) {
106 System.err.printf("%s: %03d: ", prefix, i);
107 for(int j=0; j<8 && i<len; j++, i++) {
108 final int v = 0xFF & data[offset+i];
109 System.err.printf(toHexBinaryString(v, 8)+", ");
110 }
111 System.err.println("");
112 }
113 }
114 public static final void dumpData(final String prefix, final ByteBuffer data, final int offset, final int len) {
115 for(int i=0; i<len; ) {
116 System.err.printf("%s: %03d: ", prefix, i);
117 for(int j=0; j<8 && i<len; j++, i++) {
118 final int v = 0xFF & data.get(offset+i);
119 System.err.printf(toHexBinaryString(v, 8)+", ");
120 }
121 System.err.println("");
122 }
123 }
124
125 public static int getOneBitCount(final String pattern) {
126 int c=0;
127 for(int i=0; i<pattern.length(); i++) {
128 if( '1' == pattern.charAt(i) ) {
129 c++;
130 }
131 }
132 return c;
133 }
134 public static long toLong(final String bitPattern) {
135 return Long.valueOf(bitPattern, 2).longValue();
136 }
137 public static int toInteger(final String bitPattern) {
138 final long res = Long.valueOf(bitPattern, 2).longValue();
139 if( res > UNSIGNED_INT_MAX_VALUE ) {
140 throw new NumberFormatException("Exceeds "+toHexString(UNSIGNED_INT_MAX_VALUE)+": "+toHexString(res)+" - source "+bitPattern);
141 }
142 return (int)res;
143 }
144
145 public static String toHexString(final int v) {
146 return "0x"+Integer.toHexString(v);
147 }
148 public static String toHexString(final long v) {
149 return "0x"+Long.toHexString(v);
150 }
151 public static final String strZeroPadding= "0000000000000000000000000000000000000000000000000000000000000000"; // 64
152 public static String toBinaryString(final int v, final int bitCount) {
153 if( 0 == bitCount ) {
154 return "";
155 }
156 final int mask = (int) ( ( 1L << bitCount ) - 1L );
157 final String s0 = Integer.toBinaryString( mask & v );
158 return strZeroPadding.substring(0, bitCount-s0.length())+s0;
159 }
160 public static String toBinaryString(final long v, final int bitCount) {
161 if( 0 == bitCount ) {
162 return "";
163 }
164 final long mask = ( 1L << bitCount ) - 1L;
165 final String s0 = Long.toBinaryString( mask & v );
166 return strZeroPadding.substring(0, bitCount-s0.length())+s0;
167 }
168 public static String toHexBinaryString(final long v, final int bitCount) {
169 final int nibbles = 0 == bitCount ? 2 : ( bitCount + 3 ) / 4;
170 return String.format((Locale)null, "[%0"+nibbles+"X, %s]", v, toBinaryString(v, bitCount));
171 }
172 public static String toHexBinaryString(final int v, final int bitCount) {
173 final int nibbles = 0 == bitCount ? 2 : ( bitCount + 3 ) / 4;
174 return String.format((Locale)null, "[%0"+nibbles+"X, %s]", v, toBinaryString(v, bitCount));
175 }
176 public static String toHexBinaryString(final short v, final int bitCount) {
177 final int nibbles = 0 == bitCount ? 2 : ( bitCount + 3 ) / 4;
178 return String.format((Locale)null, "[%0"+nibbles+"X, %s]", v, toBinaryString(v, bitCount));
179 }
180}
com.jogamp.common.util.BitDemoData
Definition: BitDemoData.java:34
com.jogamp.common.util.BitDemoData.testIntMSB_rev
static final int testIntMSB_rev
Definition: BitDemoData.java:84
com.jogamp.common.util.BitDemoData.testStringsLSB_revByte
static final String[] testStringsLSB_revByte
Definition: BitDemoData.java:101
com.jogamp.common.util.BitDemoData.testStringsMSB
static final String[] testStringsMSB
Definition: BitDemoData.java:77
com.jogamp.common.util.BitDemoData.getOneBitCount
static int getOneBitCount(final String pattern)
Definition: BitDemoData.java:125
com.jogamp.common.util.BitDemoData.testStringsMSB_rev
static final String[] testStringsMSB_rev
Definition: BitDemoData.java:85
com.jogamp.common.util.BitDemoData.strZeroPadding
static final String strZeroPadding
Definition: BitDemoData.java:151
com.jogamp.common.util.BitDemoData.testStringLSB_revByte
static final String testStringLSB_revByte
Definition: BitDemoData.java:102
com.jogamp.common.util.BitDemoData.testBytesMSB_rev
static final byte[] testBytesMSB_rev
Definition: BitDemoData.java:83
com.jogamp.common.util.BitDemoData.testStringMSB
static final String testStringMSB
Definition: BitDemoData.java:78
com.jogamp.common.util.BitDemoData.testBytesLSB_revByte
static final byte[] testBytesLSB_revByte
Definition: BitDemoData.java:99
com.jogamp.common.util.BitDemoData.toBinaryString
static String toBinaryString(final int v, final int bitCount)
Definition: BitDemoData.java:152
com.jogamp.common.util.BitDemoData.toHexString
static String toHexString(final long v)
Definition: BitDemoData.java:148
com.jogamp.common.util.BitDemoData.toHexBinaryString
static String toHexBinaryString(final short v, final int bitCount)
Definition: BitDemoData.java:176
com.jogamp.common.util.BitDemoData.toHexBinaryString
static String toHexBinaryString(final long v, final int bitCount)
Definition: BitDemoData.java:168
com.jogamp.common.util.BitDemoData.testStringMSB_rev
static final String testStringMSB_rev
Definition: BitDemoData.java:86
com.jogamp.common.util.BitDemoData.UNSIGNED_INT_MAX_VALUE
static final long UNSIGNED_INT_MAX_VALUE
Definition: BitDemoData.java:35
com.jogamp.common.util.BitDemoData.toHexBinaryString
static String toHexBinaryString(final int v, final int bitCount)
Definition: BitDemoData.java:172
com.jogamp.common.util.BitDemoData.toHexString
static String toHexString(final int v)
Definition: BitDemoData.java:145
com.jogamp.common.util.BitDemoData.dumpData
static final void dumpData(final String prefix, final ByteBuffer data, final int offset, final int len)
Definition: BitDemoData.java:114
com.jogamp.common.util.BitDemoData.testIntLSB_revByte
static final int testIntLSB_revByte
Definition: BitDemoData.java:100
com.jogamp.common.util.BitDemoData.testBytesLSB
static final byte[] testBytesLSB
Definition: BitDemoData.java:91
com.jogamp.common.util.BitDemoData.pyramid32bit_one
static final String[] pyramid32bit_one
Definition: BitDemoData.java:37
com.jogamp.common.util.BitDemoData.toInteger
static int toInteger(final String bitPattern)
Definition: BitDemoData.java:137
com.jogamp.common.util.BitDemoData.testStringsLSB
static final String[] testStringsLSB
Definition: BitDemoData.java:93
com.jogamp.common.util.BitDemoData.testIntLSB
static final int testIntLSB
Definition: BitDemoData.java:92
com.jogamp.common.util.BitDemoData.toBinaryString
static String toBinaryString(final long v, final int bitCount)
Definition: BitDemoData.java:160
com.jogamp.common.util.BitDemoData.testStringLSB
static final String testStringLSB
Definition: BitDemoData.java:94
com.jogamp.common.util.BitDemoData.dumpData
static final void dumpData(final String prefix, final byte[] data, final int offset, final int len)
Definition: BitDemoData.java:104
com.jogamp.common.util.BitDemoData.testIntMSB
static final int testIntMSB
Definition: BitDemoData.java:76
com.jogamp.common.util.BitDemoData.toLong
static long toLong(final String bitPattern)
Definition: BitDemoData.java:134
com.jogamp.common.util.BitDemoData.testBytesMSB
static final byte[] testBytesMSB
Definition: BitDemoData.java:75