Converting String to RGB or hex

I've got string
"C0C0C0"
which is grey color, and I have to convert it to int:
0xC0C0C0
is that possible in J2ME?

Cinnam wrote:
There's no such constructor in MIDP. You'll have to use
int hexInt = Integer.parseInt("C0C0C0", 16);
yeah thats right. i kinda wrote that in a hurry
to err is human, forgive divine.

Similar Messages

  • Problem in Converting String (containing arabic) to HEX

    Hi,
    I am trying to convert Arabic Text stored in a String into HEX format.
    The arabic range in unicode is: 0600�06FF
    But when i convert using Integer.toHexString(), i get hex values which are not in the above range.
    Here goes the code:
    for(int i=0;i<text1.length();i++)
    if((int)text1.charAt(i)<10) {
    hextext+="0"+Integer.toHexString(text1.charAt(i)).toUpperCase();
    else {
    hextext+=Integer.toHexString(text1.charAt(i)).toUpperCase();
    Regards,

    http://forum.java.sun.com/thread.jspa?threadID=682398&messageID=3975945#3975945

  • Converting byte from dec to hex

    Hi All,
    I'm having a problem converting byte from decimal to hex - i need the following result:
    if entered 127 (dec), the output should be 7f (hex).
    The following method fails, of course because of NumberFormatException.
        private byte toHexByte(byte signedByte)
            int unsignedByte = signedByte;
            unsignedByte &= 0xff;
            String hexString = Integer.toHexString(unsignedByte);
            BigInteger bigInteger = new BigInteger(hexString);
            //byte hexByte = Byte.parseByte(hexString);
            return bigInteger.byteValue();
        }

    get numberformatexception because a lot of hex digits cannot be transformed into int just like that (ie f is not a digit in decimal) heres some code that i used for a pdp11 assembler IDE... but this is for 16-bit 2s complement in binary/octal/decimal/hex , might be useful for reference as example though
        public static String getBase(short i, int base){
            String res = (i>=0)? Integer.toString((int)i,base)
                    : Integer.toString((int)65536+i,base) + " ("+Integer.toString((int)i,base)+")";
           StringBuffer pad= new StringBuffer();
            for(int x = 0; x < 16 - res.length() ; x++){
                pad.append("0");
            res = pad.toString() + res;
            return res;
        }

  • Checking and Converting binary, octal, decimal, and hex

    Hi,
    I have a classroom project which will need to validate that data entered in a text is of a certain type with a keyListener, and then convert that value to the other 3 types.
    I know character.isDigit will handle the decimal case, and that I can then use Integer.otString methods to convert to binary, octal, and hex, but what about the other cases?
    Thanks

    OK, this isn't working. If I've already established
    that the string entered into, for example, the
    integer-only textfield is a valid integer, I should be
    able to simply use integer.parseint(s, 2) to convert
    it into binary, right?Not exactly. You should be able to use Integer.parseInt(s, 2) to return the result of converting it from binary representation. You appear to think that this affects whatever "s" refers to, which is not the case. Note also, that method returns an int which is the decimal value in question.
    When you are thinking of int variables, be careful not to think of them as "decimal" or "binary". They are neither. They are just numbers. "Decimal" and "binary" are text representations of numbers, so those concepts can only be applied to strings.
    Integer.parseInt(s, 2);
    txtBin.setText(s);So here you want to assume that the input is a string that represents a number in decimal, and you want to find the string that represents the number in binary. Like this:// convert string in decimal representation to number
    int dec = Integer.parseInt(s);
    // convert int to binary representation as string:
    String binary = Integer.toBinaryString(dec);
    // write that to the text field
    txtBin.setText(binary);You could use a one-liner to do that, but you'll need the "dec" variable to set the other text boxes.
    Rembering why I hate OO...All of what I said there is true in just about all computer languages, OO or otherwise.
    PC&#178;

  • Convert FF Ascii To FF Hex

    I have a serial device that returns a hex number but in ascii format(!).
    For example:
    Instead of returning  FF0A (viewed in a string indicator set to Hex display), it returns ff0a (as viewed in a string indicator set to normal display). But the data actually represents FF 0A.
    My question is how can I convert ff0a (ascii) to FF 0A (hex)?
    Thanks in advance!
    Solved!
    Go to Solution.

    Hexadecimal String to Number.
    Remember:
    The LabVIEW Help is there to help you.  
    The functions palette has a search capabitility.
    Message Edited by smercurio_fc on 06-15-2010 09:22 AM
    Attachments:
    Example_VI_BD.png ‏1 KB

  • Not able to convert string attribute to number and date please help me out

    not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • How can I convert Pdf from RGB to CMYK, keeping font color 100% K while working in Illustrator?

    How can I convert Pdf from RGB to CMYK, keeping font color 100% K while working in Illustrator?
    When I try to open the document in Illustrator and I convert to CMYK the black font converts to rich black, but to set up for Offset printintg I need the text to be only in Black (100%K).
    The original source of the document is a Microsoft Word file, I have converted the Word file to Pdf in order to setup for OFfset Printing.
    Thanks

    I have tried that way, but the downside is that the fonts are set in gray not in a 100%K, also I have to deal with other fonts that are composites and meant to stay Full Color. I could select text by text and convert to gray but, its a 64 page document and I wouldn't want to make a expensive mistake.

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

  • How to convert string to an integer in SQL Server 2008

    Hi All,
    How to convert string to an integer in sql server,
    Input : string str="1,2,3,5"
    Output would be : 1,2,3,5
    Thanks in advance.
    Regards,
    Sunil

    No, you cannot convert to INT and get 1,2,3 BUT you can get
    1
    2
    3
    Is it ok?
    CREATE FUNCTION [dbo].[SplitString]
             @str VARCHAR(MAX)
        RETURNS @ret TABLE (token VARCHAR(MAX))
         AS
         BEGIN
        DECLARE @x XML 
        SET @x = '<t>' + REPLACE(@str, ',', '</t><t>') + '</t>'
        INSERT INTO @ret
            SELECT x.i.value('.', 'VARCHAR(MAX)') AS token
            FROM @x.nodes('//t') x(i)
        RETURN
       END
    ----Usage
    SELECT * FROM SplitString ('1,2,3')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to convert String (dd-MMM-yyyy) to oracle.jbo.domain.Date

    Hi
    Could you please tell how do I convert String of date in format dd-MM-yyyy to ADF date? Please show me some sample.
    Thanks

    http://javaalmanac.com/egs/java.text/FormatDateDef.html
    Once you have a java.util.Date you can convert it to oracle.jbo.domain.Date. (see http://www.fifkredit.com/bc4jdoc/rt/oracle/jbo/domain/Date.html)

  • How to convert CMYK to RGB programmatically.

    Hi,
    I have a CMYK colorspace in indesign, i want to convert that as RGB color space, I got some codes, but I am getting incorrect data.
    Some of the codes which I tried are given below
            double cyan = 35.0;
            double magenta = 29.0;
            double yellow = 0.0;
            double black = 16.0;
            cyan = Math.min(255, cyan + black); //black is from K
            magenta = Math.min(255, magenta + black);
            yellow = Math.min(255, yellow + black);
            l_res[0] = 255 - cyan;
            l_res[1] = 255 - magenta;
            l_res[2] = 255 - yellow;
    @Override
        public float[] toRGB(float[] p_colorvalue) {
            float[] l_res = {0,0,0};
            if (p_colorvalue.length >= 4)
                float l_black = (float)1.0 - p_colorvalue[3];
                l_res[0] = l_black * ((float)1.0 - p_colorvalue[0]);
                l_res[1] = l_black * ((float)1.0 - p_colorvalue[1]);
                l_res[2] = l_black * ((float)1.0 - p_colorvalue[2]);
            return (l_res);
    The values are C=35, M = 29, Y = 0, K = 16 in CMYK color space and the correct RGB values are R = 142, G = 148, B = 186.
    In adobe indesign, using swatches we can change the mode to CMYK or to RGB.
    But I want to do that programmatically, Can I get any algorithm to convert CMYK to RGB which will give the correct RGB values.
    And one more question, if the alpha value for RGB is 1 then what will be the alpha value for CMYK?
    Can anyone help me to solve these issues... Thanks in advance.

    All you have to do is loop thru the swatches and change the space to RGB. Below is an AppleScript, but it shouldn't be too difficult to come up with the equivalent JavaScript. Your document's assigned RGB space will determine what RGB space the CMYK converts to, so if you are looking for sRGB, then Edit>Assign Profiles...>Assign Profile: sRGB
    tell application "Adobe InDesign CS3"
    tell document 1
    repeat with a from 1 to count of every swatch
    try
    set space of color a to RGB
    end try
    end repeat
    display dialog "All swatches have been converted to RGB color"
    end tell
    end tell

  • Facing problem in converting string to date using getOANLSServices()

    I am trying to set a value for date field in my vo and trying to insert into the table.
    In controller I am getting the String which has a date:
    ex: String date="01-NOV-2007";
    while setting into the row I need to convert into Date but it is returning null.
    The below code I used
    to convert into date :
    Date dt = new Date(getOADBTransaction().getOANLSServices().stringToDate(date));
    But this dt is returning a null value is there any solution please advise me.
    Regards!
    Smarajeet

    Smarajeet ,
    See this thread, in one of my replies i have mentioned how to convert string to java.sql.date.You can use the same for oracle.jbo.domain.Date.
    urgent!How to set the default selected date for an OAMessageDateFieldBean
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Converting String To XML Format and send as attachment

    Hi
    My requirement is to convert String into XML Format and that XML File i have to send as an attachment
    can any one one give solution for this Problem.
    Thank you
    Venkatesh.K

    hi,
    i m filling the itab first and converting to xml
    itab contaning these data
    GS_PERSON-CUST_ID   = '3'.
    GS_PERSON-FIRSTNAME = 'Bill'.
    GS_PERSON-LASTNAME  = 'Gates'.
    APPEND GS_PERSON TO GT_PERSON.
    GS_PERSON-CUST_ID   = '4'.
    GS_PERSON-FIRSTNAME = 'Frodo'.
    GS_PERSON-LASTNAME  = 'Baggins'.
    APPEND GS_PERSON TO GT_PERSON.
    after conversion data is coming like that
    #<?xml version="1.0" encoding="utf-16"?>
    <CUSTOMERS>
      <item>
        <customer_id>0003</customer_id>
        <first_name>Bill</first_name>
        <last_name>Gates</last_name>
      </item>
      <item>
        <customer_id>0004</customer_id>
        <first_name>Frodo</first_name>
        <last_name>Baggins</last_name>
      </item>
    </CUSTOMERS>
    but errors are  1) # is coming at the first
                            2)for 'encoding="utf-16"?>', it is not coming perfectly, some other data (iso-8859-1) should come here
    can anybody plz solve it.
    regards,
    viki

  • Converting string to XML format

    Hi All,
    I have a requirement to convert string to xml format and download it. Atpresent, I have a string which is a collection of xml tags. I want to convert this string to xml format like <VALUE004>20387899.437</VALUE004>
    <VALUE005>20387899.437</VALUE005>
    <VALUE006>20387899.437</VALUE006>
    Is there any function module for this.

    Chk this thread.
    Re: Regd: File Conversion to XML format

Maybe you are looking for

  • It has been a real headache

    I have been a Best Buy Rewards member for years and years.  The past couple of years I have been Elite Plus.  Sometime in the past 6 months an additional BB Rewards account was opened in my name and all of my purchases have been being placed on that

  • Photoshop CS 6 Fails to install

    Hi, I'm trying to install Photoshop CS6 trial on a Alienware MX17 Windows 7 64bit laptop, and it fails everytime. My videoo drivers are the latest it's possible to get, I also have all the latest windows updates installed. It goes through to the "Cur

  • How to delete tracks from iOS device?

    Hello! Could somebody help me with a problem? How can I delete tracks, stored in my device memory (im usuing iPhone 4) when itunes match mode turned on? "Swipe to delete" on tracks/artist doesn't work. So the swipe works only when itunes match mode i

  • Slideshow on tv with accompanying music

    How do you get music to play along with a photo slideshow either on tv or on the ipod itself ipod 5th generation 30 gb    

  • Leasing sub contract item

    hi friends,     for the item in sub contract change process lcop is done.  so this is marked as completed and new line item is created with the all the changes is required. but using this new item i need to find the old sub contract item. can anyone