Char to bit string???

Hi everyone,
I have a small problem and I was wondering if anyone can help. I want to convert a char value to a string of bits. I have had no problem doing it with an integer but I "keep reaching for the Aspirin" when it comes to the char. Any ideas? I am sure I am doing something stupid - it should be relatively simple.

Here's the general idea:private static String toBitString(char c) {
    return Integer.toBinaryString(c);
private static String toFixedLengthBitString(char c) {
    return Integer.toBinaryString(c | 0x10000).substring(1);
}

Similar Messages

  • 16-bit string literals

    How can you specify a string literal that compiles to an array of 16-bit units? "string" compiles to 1-byte char* and L"string" compiles to 4-byte wchar_t but we need a syntax to specify a string of 2-byte unsigned short.

    I'm reasonably confident that there is no 16-bit driver that works with an 8i client. I'd suspect that the old 16-bit drivers can probably be used to connect to an 8i database from an older client.
    Justin

  • How to delete the last char in a String?

    i want to delete the last char in a String, but i don't want to convert the String to a StringBuffer or an array, who knows how to do?

    Try it in this way
    String MyString = "ABCDEF";
    MyString = MyString.substring(0,MyString.length()-1);

  • Create an image from a bit String

    Hi everybody
    I don't know if this is the correct forum for this so first of all sorry if I did it wrong. I have never created an image in Java so I am a little bit lost with my new task.
    I have a bit String (for example "00111010") and I want to create an image converting the 0-s into white pixels and 1-s into black ones. The new image should be 8x1 pixels (for the previous example would be white-white-black-black-black-white-black-white).
    As I have explained before, I have never done something similar so I don't know how easy is my problem to resolve. Any help?

    read up on Java2D and image processing
    try some tutorials
    basically you need to convert your data to an intensity map
    there's a couple ways to do it
    i'd convert to a byte or int array which you can pass into the image constructors
    try and get started then come back here when/if you have specific problems

  • How to read char() for bit data DB2's type in Oracle?

    Hello,
    I am developing an application (from JDeveloper) to operate with two data base. In one hand threre is Oracle and in the other one DB2 (AS400).
    I am trying to read a DB2'sfield with the "char() for bit data" type from Oracle, but I can't read it.
    I have trying:
    rset.getObject(1) -->[B@1a786c3
    rset.getBinaryStream(1) --> java.io.ByteArrayInputStream@1a786c3
    rset.getAsciiStream(1) --> java.io.ByteArrayInputStream@2bb514
    rset.getCharacterStream(1) -->java.io.StringReader@1a786c3
    Do you have any solution to see the value of this type of field?
    Thank you and regards

    I have to synchronize unidirectionally from the Oracle database to DB2. And I'd like to save the information of the record of DB2 prior to the update operation.
    And here is where the problem arises for me, because when I try to read from Java with the connection established on DB2 is unable to interpret the information. While there are no problems from Oracle to consume the information, it happens that DB2 field types are not common with Oracle, such as char () for bit data. From what I could find the equivalent in Oracle would be raw (), but since Java is possible to read this type of information... And this is my doubt, it is necessary to do any type of cast or to do a special view to retrieve this information?

  • Deleting the last char of a string

    How can I Delete the last char of a string???
    example:
    asd@fdg@vvdfgfd@gdgdfgfd@gdfgdf@
    I want delete the last @!
    Tks in advance!

    hi,
    try this:
    lv_count = strlen(string).
    lv_count_last = lv-count - 1.
    replace string+lv_count_last(lv_count) in string by ' '.
    This should work.
    thnx,
    ags.
    Edited by: Agasti Kale on Jun 4, 2008 9:03 PM

  • How to remove last char in a string by space

    I have to implement backspace application(remove a last char in a string , when we pressed a button).
    for ex: I enter the no
    1234
    instead of 1236
    So when i press a button on the JWindow... it should display
    123
    so that i can enter 6 now.
    I tried to display the string "123 " instead over "1234" but it is not working when the no background is specified. but works fine when a background color is specified.
    The string is displayed as
    Graphics2D g = (Graphics2D)window.getGraphics();
    AttributedString as = new AttributedString(string, map);
    g.drawString(as.getIterator(),x,y);
    In the map, the background is set to NO_BACKGROUND.
    Thanks and regards

    Deja vu. I saw this kind of post before, and I'm sure
    it was today.http://forum.java.sun.com/thread.jspa?threadID=588110&tstart=0
    Here it is.

  • Deleting last char in a string...

    I have a string that is created as follows: strBuffer += k.getKeyChar();(k is KeyPressed ...KeyEvent) How can I delete the last Char in the string strBuffer?

    Hi
    // simply substring
    if (strBuffer.length() > 1)
        strBuffer = strBuffer.substring(0, strBuffer.length()-1);
    // you may also use
    if (strBuffer.length() > 1)
        StringBuffer buffer = new StringBuffer(strBuffer).
                                   deleteCharAt(strBuffer.length()-1);
        strBuffer = buffer.toString();
    }I've not tested the above code myself & I've written the above code on the go after reading your query. The above code definitely work & help you.
    Regards,
    JPassion

  • Finding last char in the string

    Hi
    i need to find out whether the last char of a string is '/' (forward slash). please let me know if there's a FM to do that. Other post me the logic for this ASAP.
    thanks

    len = strlen(char).
    len = len - 1.
    if char+len(1) = '/'.
      *write ur code
    endif.
    chk this code
    REPORT ychatest.
    DATA : str(5) VALUE '123/',
           len TYPE i.
    len = STRLEN( str ).
    len = len - 1.
    IF str+len(1) = '/'.
      WRITE : '/ found'.
    ENDIF.
    <b>Reward points if helpful and close thrad if solved</b>
    Message was edited by: Chandrasekhar Jagarlamudi

  • Compare individual char of 2 string

    Hi
    I need to compare the each individual char of 2 string.
    String a = "Ae12";
    String b = "aE12";
    // I tried the followings:
    // a
    String c = a.substring(0,0);
    String d = a.substring(1,1);
    String e = a.substring(2,2);
    String f = a.substring(3,3);
    // b
    String c1 = b.substring(0,0);
    String d1 = b.substring(1,1);
    String e1 = b.substring(2,2);
    String f1 = b.substring(3,3);
    if(c.equalsIgnoreCase(c1)&&d.equalsIgnoreCase(d1)&&e.equalsIgnoreCase(e1)&&f.equalsIgnoreCase(f1)) // Cannot be compared
    // and I tried the followings:
    // a
    char c = a.charAt(0);
    char d = a.charAt(1);
    char e = a.charAt(2);
    char f = a.charAt(3);
    // b
    char c1 = b.charAt(0);
    char d1 = b.charAt(1);
    char e1 = b.charAt(2);
    char f1 = b.charAt(3);
    if(c==c1&&d==d1&&e==e1&&f==f1) // cannot be compared.
    Both cases cannot be compared. How can I fix it?
    Because I want to compare those 2 strings without case sensitive and numbers.
    Thanks

    techissue2008 wrote:
    String a = "Ae12";
    String b = "aE12";
    Then, are "Ae12" and "aE12" the same when ignore case?
    If so, the Strings are actually the same.No, the Strings are not the same, if by same, you mean the "same" Object, or the "same" value when case is not ignored, but they are the "same" value when case is ignored.
    This prints true (try it yourself), as it should
    public class Test {
      public static void main (String[] args) {
        System.out.println("aE12".equalsIgnoreCase("Ae12"));
    }They are still two distinct instances with two distinct values however, so where, exactly, is your problem?

  • Finding char in a string

    Hi,
    In C there is a function strchr() to find a char in a string. Is there an equivalent funtion in Java?
    The function indexOf() returns an int, but I want this char search would return a boolean value.
    So help please, thanks a lot
    chanh

    public boolean strchr(char myChar, String myString){
       for(int j = 0; j < myString.length(); j++){
          if(myChar == myString.charAt(j) return true;
       return false;
    }Is this what you are looking for?

  • How to get a char from a String Class?

    How to get a char from a String Class?

    Use charAt(int index), like this for example:
    String s = "Java";
    char c = s.charAt(2);
    System.out.println(c);

  • How to invoke the char " in a string?

    Hi!
    I�m trying to invoke the char " in a string and I can�t think of any good way to do that.
    plz help.

    use
    String foo = new String("the string foo has the \"a string\" value");

  • How to take last 5 char from a string

    Hi All
    I have a requirement,
    base on some comp i have to populate another field.
    in this case i have compare last 3 char of a string 
    example if total string say asasdffrx i have to take last three char here it is frx.
    always i have to last 3 char.
    i can use +6(3) but it wont work every time because string lenght is not fix for all vaue.
    thanks

    Hi,
    A.H.P sample is ok but insert additional check for strigs shorter than 3 (to avoid negative offset):
    data : n TYPE I.
    n = STRLEN( zfield ) - 3.
    if n >= 0.
    result = zfield+n(3).
    else.
    result = zfield.
    endif.
    Krzys

  • Comparing a char to a string value

    hello.
    i would like to take a string, take the first value, see if it is equal to something, and based on that condition, proceed through some conditional statements.
    i tried this, but doesnt work.
    String path;
    char c = path.charAt( 0 );
    if ( c.equals("/") ) {
    Blah
    ive also tried to cast the char as a String and it didnt work.
    if ( ( (String)c ).equals("/") ) {i originally tried
    any ideas?
    thanks.
    J                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    >
    any ideas?I always liked...
      switch(path.charAt(0))
         case '/': ....

Maybe you are looking for