mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-3265 fix bit twiddling in NumericUtilities.toHexString()
This commit is contained in:
@@ -15,12 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package ghidra.util;
|
package ghidra.util;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.apache.commons.collections4.IteratorUtils;
|
import org.apache.commons.collections4.IteratorUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@@ -217,7 +218,7 @@ public final class NumericUtilities {
|
|||||||
*/
|
*/
|
||||||
public final static String toHexString(long value, int size) {
|
public final static String toHexString(long value, int size) {
|
||||||
if (size > 0 && size < 8) {
|
if (size > 0 && size < 8) {
|
||||||
value &= -1L >> (8 * (8 - size));
|
value &= -1L >>> (8 * (8 - size));
|
||||||
}
|
}
|
||||||
return HEX_PREFIX_x + Long.toHexString(value);
|
return HEX_PREFIX_x + Long.toHexString(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package ghidra.util;
|
package ghidra.util;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -314,6 +315,13 @@ public class NumericUtilitiesTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToHexString() {
|
||||||
|
for (int sizeofValue = 1; sizeofValue <= 8; sizeofValue++) {
|
||||||
|
assertEquals("0x" + "ff".repeat(sizeofValue), NumericUtilities.toHexString(-1, sizeofValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void asssertBytesEquals(byte[] expected, byte[] actual) {
|
private void asssertBytesEquals(byte[] expected, byte[] actual) {
|
||||||
|
|
||||||
String errorMessage = "Byte arrays not equal - exptected: " + Arrays.toString(expected) +
|
String errorMessage = "Byte arrays not equal - exptected: " + Arrays.toString(expected) +
|
||||||
|
|||||||
Reference in New Issue
Block a user