Example usage for java.lang Integer toHexString

List of usage examples for java.lang Integer toHexString

Introduction

In this page you can find the example usage for java.lang Integer toHexString.

Prototype

public static String toHexString(int i) 

Source Link

Document

Returns a string representation of the integer argument as an unsigned integer in base 16.

Usage

From source file:com.thoughtworks.xstream.benchmark.reflection.targets.AbstractReflectionTarget.java

protected void fill(final Object o) {
    final char[] zero = new char[8];
    Arrays.fill(zero, '0');
    for (Class cls = o.getClass(); cls != Object.class; cls = cls.getSuperclass()) {
        final Field[] fields = cls.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            final Field field = fields[i];
            field.setAccessible(true);//from  w ww.  ja  v  a2 s .  co  m
            if (field.getType() == String.class) {
                final String hex = Integer.toHexString(i);
                try {
                    field.set(o, new String(zero, 0, zero.length - hex.length()) + hex);
                } catch (final IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}

From source file:com.nikonhacker.emu.memory.AutoAllocatingMemory.java

/**
 * Perform a byte load where the sign extended result fills the return value
 *
 * @param addr the address of the value to load
 * @return the sign extended result/*  w  w  w . j  a  v a2s  .  c  o m*/
 */
final public int loadSigned8(int addr) {
    try {
        if (logMemoryMessages)
            System.err.println("LoadS8 address: 0x" + Integer.toHexString(addr) + " val: "
                    + readableMemory[getPTE(addr)][getOffset(addr)]);

        byte[] pageData = readableMemory[getPTE(addr)];
        if (pageData == null) {
            map(truncateToPage(addr), PAGE_SIZE, true, true, true);
            pageData = readableMemory[getPTE(addr)];
        }

        return pageData[getOffset(addr)];
    } catch (NullPointerException e) {
        System.err.println("Null pointer exception at address: 0x" + Integer.toHexString(addr));
        throw e;
    }
}

From source file:RemarksText.java

public RemarksText() {
    shell.setLayout(new GridLayout(1, false));

    (new Label(shell, SWT.NULL)).setText("Remarks:");

    text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    text.setText("123456789");

    text.setLayoutData(new GridData(GridData.FILL_BOTH));

    System.out.println("getText: " + text.getText(1, 6));

    char[] chars = text.getLineDelimiter().toCharArray();
    for (int i = 0; i < chars.length; i++) {
        System.out.println("Line delimiter #" + i + ": " + Integer.toHexString(chars[i]));
    }//  w  w w.j a v  a2s  .c o m

    text.getOrientation();

    System.out.println("Number of chars: " + text.getCharCount());
    System.out.println("Tabs: " + text.getTabs());

    text.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent e) {
            if (e.end == e.start) {
                if (e.character == ' ' && (e.stateMask & SWT.CTRL) != 0) {
                    if (text.getText(e.end - 1, e.end - 1).equals("V")) {
                        e.text = "erifyListener";
                    } else {
                        e.doit = false;
                    }
                }
            }
        }
    });

    text.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            System.out.println("New character count: " + text.getCharCount());
        }
    });

    // text.append("a");

    text.setSelection(1, 4);

    System.out.println("getSelection:\t" + text.getSelection());
    System.out.println("getSelectionCount:\t" + text.getSelectionCount());
    System.out.println("getSelectionText:\t" + text.getSelectionText());
    //text.insert("ABC");

    init();

    // shell.pack();
    shell.setSize(300, 150);
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:Service.FichierServiceImpl.java

private static String hashNomFichier(String nomFichier) {
    byte[] uniqueKey = nomFichier.getBytes();
    byte[] hash = null;

    try {/*from  w ww. j av a 2s  . co m*/
        hash = MessageDigest.getInstance("MD5").digest(uniqueKey);
    } catch (NoSuchAlgorithmException e) {
        throw new Error("No MD5 support in this VM.");
    }

    StringBuilder hashString = new StringBuilder();
    for (int i = 0; i < hash.length; i++) {
        String hex = Integer.toHexString(hash[i]);
        if (hex.length() == 1) {
            hashString.append('0');
            hashString.append(hex.charAt(hex.length() - 1));
        } else {
            hashString.append(hex.substring(hex.length() - 2));
        }
    }
    return hashString.toString();
}

From source file:Main.java

public static String getStringFromBytes(byte[] bytes) {
    StringBuilder sb = new StringBuilder(bytes.length * 3);
    for (byte b : bytes) {
        String hex = Integer.toHexString(0xFF & b);
        if (hex.length() == 1)
            hex = '0' + hex;

        sb.append(hex + ' ');
    }/*from   ww w  .  ja va2 s  .  c  o  m*/

    return sb.toString();
}

From source file:com.bstek.dorado.util.StringAliasUtils.java

private static String toHexString(char c) {
    if (c > 127) {
        throw new IllegalArgumentException("Unsupported char [" + c + "].");
    }//  w  w  w  .ja  v a2  s .  c  o m

    String s = Integer.toHexString(c);
    if (s.length() == 1)
        return '0' + s;
    else
        return s;
}

From source file:de.tobiasbruns.fs20.sender.FS20SenderService.java

public String getFirmwareVersion() {
    FS20Result result = executeRequest(new FirmwareRequest());
    char[] versionArray = Integer.toHexString(result.getPayload() & 0xffff).toCharArray();
    return versionArray[0] + (versionArray.length > 1 ? "." + versionArray[1] : "");
}

From source file:com.glaf.core.security.SecurityUtils.java

/**
 * /* w  w  w .  j  a v a 2 s  .co m*/
 * 
 * @param b
 * @return
 */
private static String byte2hex(byte[] b) {
    StringBuilder hs = new StringBuilder();
    String stmp;
    for (int n = 0; b != null && n < b.length; n++) {
        stmp = Integer.toHexString(b[n] & 0XFF);
        if (stmp.length() == 1) {
            hs.append('0');
        }
        hs.append(stmp);
    }
    return hs.toString().toUpperCase();
}

From source file:com.opengamma.integration.tool.portfolio.xml.v1_0.conversion.AbstractListedSecurityExtractor.java

@Override
public ManageableSecurity[] extract() {
    ManageableSecurity security = createSecurity();
    security.addExternalId(ExternalId.of("XML_LOADER", Integer
            .toHexString(new HashCodeBuilder().append(security.getClass()).append(security).toHashCode())));
    security.setAttributes(getSecurityDefinition().getAdditionalAttributes());
    return new ManageableSecurity[] { security };
}