Decimal to Hex

I've been banging my head against the desk for hours on this one. I really need to write a Java applet to convert decimals to hex, I really would appreciate any help given with this one. So far I only have this;
value1 = (decimal % 16);
problem is, I don't know how to get the value and then do the calculation again. I know that I should be using some sort of do/while loop, with a while(somevalue!=0) at the end, but thats about it.

I can do it easily using a pen an paper.
Get the decimal number e.g 50
Divide it by the hex base 16, equals 3 remainder 2
Divide 3 by 16, equals 0 remainder 3
the answer is the two remainder from the bottom added, 32.
The problem I'm having is that I don't know how to get the new value i.e 3 and then divide it by 16, and then if required, divide it by 16 again. I'm not to worried about converting A to 10 and such yet, I just need help getting the value and dividing it by 16 over and over and then recording each the answer each time.

Similar Messages

  • Decimal to hex convert

    Hello,
    sorry but i have a simple question. I want to convert decimal number 0-10000 (like 10000 (decimal) to 27 and 10 (hex) or 1000 (decimal) to  03 and E8 (hex)) to two hex numbers and back. Iám searching for an easy way.
    I tried different ways but i can`t find a solution.
    greetings Schwede
    Message Edited by Schwede on 12-10-2008 07:11 AM
    Solved!
    Go to Solution.

    A very quick an easy method. For numbers go to palette numeric>>data manipulation>>join numbers and split numbers
    Message Edited by t06afre on 12-10-2008 07:59 AM
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)
    Attachments:
    sample.vi ‏34 KB

  • Converting decimal to hex

    Does any one have any code snippet to do this in Java ?
    one of the applications that i am building has the need to convert an incoming decimal value from a backend system to hex and take the last 2 fields of the hex value for some comparison checking.
    All help is deeply appreciated ..
    thanks
    Rox

    one of the applications that i am building has the
    need to convert an incoming decimal value from a
    backend system to hex and take the last 2 fields of
    the hex value for some comparison checking.In an int representation of a number each hex digit will occupy 4 bits, so
    int i = ....; // decimal number
    int h1 = i & 0xf; // first hex digit from the right
    int h2 = (i>>>4) & 0xf; // second hex digit

  • Convert Decimal to Hex

    I use an LDAP database that stores values in decimal format,
    but to display these values to the end user, I want them in Hex.
    For example.
    50699 becomes C60B
    and
    18743297 becomes 11E0001
    Is there a function built into CF that allows me to do this
    conversion? I can't seem to find one. Or will I have to write a
    cfscript or javascript function to do this for me?
    -xtort

    > I just found that in Ben Forda's book. That got it,
    thanks!!
    Glad you found it.
    livedocs is a good resource for those who are patient: it's a
    *very* slow
    site, especially given the simple pages it's delivering. But
    it's got
    everything you need (the annotations on the pages are often
    more useful
    that the "official" line, btw).
    A good entry point to the most important parts of livedocs
    are these:
    http://ray.camdenfamily.com/downloads/functions.html
    http://ray.camdenfamily.com/downloads/tags.html
    It cuts down quite a bit of the waiting. They;re also good
    lists to scan
    to get a handle on what CF can do, at least at an executive
    summary level.
    Adam

  • 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²

  • Exception occuring while i'm trying to convert decimal to Hex

    Hello all you genius people, please help me out. I'm using this simple code(given below) to read String from a file then convert it to Hex and write in anoher file. But i'm getting this exception that, after reading few lines it gives such exception:
    java.lang.NumberFormatException: For input string: "2826111134"
    import java.io.*;
    public class DecimalToHexConv {
      String line;
      String hexEsn;
      String temp;
      int esn=0;
      public DecimalToHexConv(){
      try{
        FileWriter fwr = new FileWriter("CTGHLR201005_out.txt");
        BufferedReader bfr = new BufferedReader(new FileReader("testin.txt"));
        while((line=bfr.readLine())!=null){
          line= line.replace('|',';');
          String spl[] = line.split(";");
          esn = Integer.parseInt(spl[2].toString().trim());
          hexEsn = (Integer.toHexString(esn)).toUpperCase();
          temp= spl[0]+"|"+spl[1]+"|"+hexEsn+"\n";
          System.out.print(temp);
          fwr.write(temp);
        fwr.close();
      catch(Exception e){
        System.out.println("Exception: "+e);
      public static void main(String[] args) throws Exception {
        DecimalToHexConv dtc = new DecimalToHexConv();
    }output:
    4702181500|11800467|2FA42C8B
    4702825345|11704172|620A4CFC
    4703200000|11200000|52B53DB9
    4703200001|11200001|52156AC7
    Exception: java.lang.NumberFormatException: For input string: "2826111134"
    testin.txt:
    4702181500|11800467|799288459
    4702825345|11704172|1644842236
    4703200000|11200000|1387609529
    4703200001|11200001|1377135303
    4703200046|11200046|2826111134
    4703200000|11200000|1387609529
    4703200001|11200001|1377135303
    So after converting first 4 lines i got the exception. Please hep me out.. that what is wrong???
    Regards
    Sahrear

    But i'm getting this exception that,
    after reading few lines it gives such exception:
    java.lang.NumberFormatException: For input string:
    "2826111134"It's because the biggest number an int can hold is 2147483647. You can use long insted. It can hold bigger numbers but understand that it has an upper limit too.

  • Convert Floating Point Decimal to Hex

    In my application I make some calculations using floating point format DBL,and need to write these values to a file in IEEE 754 Floating Point Hex format. Is there any way to do this using LabVIEW?

    Mike,
    Good news. LabVIEW has a function that does exactly what you want. It is well hidden though...
    In the Advanced/Data manipulation palette there is a function called Flatten to String. If you feed this funtion with your DBL precision digital value you get the IEEE-754 hexadecimal floating point representation (64 bit) at the data string terminal (as a text string).
    I attached a simple example that shows how it works.
    Hope this helps. /Mikael Garcia
    Attachments:
    ieee754converter.vi ‏10 KB

  • Function for converting Decimal to HEX

    Does anyone know of such a function?

    Thanks. We are still a bit confused. I have attached an email from a data supplier of ours. Can you make sense of it ???
    Page 24 says: if the bit 3 (0x08) of the field TF_FIELD_STATIC_SEC_FLAG is 1 for an US stock,
    then the stock is constituent of the NASDAQ 100 index NDX.
    Example:
    For Microsoft (MSFT) the field TF_FIELD_STATIC_SEC_FLAG has the value
    0x39 = 57 = 0x01 + 0x08 + 0x10 + 0x20
    because MSFT is constituent of the
    Dow Jones Industrial index !DJI (0x01)
    NASDAQ 100 index NDX (0x08)
    S&P 100 index OEX (0x10)
    S&P 500 index SPX (0x20)

  • Converting a hex String to its corresponding hex value...?

    Yeah, I'm having quite a bit of fun guessing this one... :p
    I have a string of n characters and have used Integer.toHexString( ( int )str.charAt( i ) ) to convert each character to a string representing its hex value. Now I need to USE that value for bit-wise operations, like, say, applying the AND, OR, etc. operators...
    Example:
    hexvalue &= 0xC000FFFF; //the second value is the one extracted from the string;
    How can achieve this...? Any help is greatly appreciated... :}

    Since a Java char is numerically a Java short, you can apply bitwise operators to chars directly - the conversion to hex simply changes the way that the char is viewed; the result can also be viewed as a number in other bases.
    For instance, the char 'A' can be also be represented as any of the following values:
    binary - 1000001
    octal - 101
    decimal - 65
    hex - 41
    Likewise, 'Z' can also be viewed as
    binary - 1011010
    octal - 132
    decimal - 90
    hex - 5A
    "Anding" the letter 'A' with 'Z' ('A' & 'Z') or doing the same using any of the other representations will result in (binary 1000000, octal 100, decimal 64, or hex 40) - the bit pattern is the same, only the representation of the result varies.

  • Convert date/time to HEX command and write to a bin file

    Hello,
    I have to do the following thing. I have the date/time string, let's say 08:45:23, 12.08.09, where the hour, the minutes, the seconds, the day, the month and the year represent hex number or in other words I have the following command:
    Byte 0 - Byte 5
    0x08; 0x45; 0x23; 0x12; 0x08; 0x09;
    Now I want to write this command in a binary file in order to send thefile later throught serial RS232 connection.
    Now, I am not sure whether I write the command in the binary file in the correct format. What I simply do is to write it as a string
    ("084523120809"). Is this the correct way. I guess no, because when transmitted it does not work as expected.
    How can I write this string as a HEX command in the binary file?
    Thanks for the replies in advance
    IG
    Message Edited by igurov on 08-12-2009 01:51 AM
    Attachments:
    1(2).JPG ‏39 KB

    Do you know the difference between decimal and hex values? It's not the same, that the whole point, and it's why it doesn't make sense. Decimal 32 is not the same as hex 32. These are two different values, even though they both have the digits "3" and "2". The hex value will be the same as the decimal value up to the value of 9. In your example the hour is 8. In decimal this is 8, in hex this is 8. The minutes is 45. That's decimal. In hex, this is 2D, not 45, as you claim in your example. Hex 45 is a completely different number (and a completely different "pattern").
    Attachments:
    time hex.vi ‏12 KB

  • 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;
        }

  • How can be represent -10 in Hex in LabVIEW

    Hello All,
    Can anybody tell me how to represent a –ve number in a Hexadecimal format? (How do u will represent -10 in Hex)
    If anybody is having any readymade utility
    Thanks and Regards.

    Lets say we have 32 bits to work with.
    The first 16 bits is for positive numbers and the last 16 bits is for negative numbers.
    Only thing you have to watch out for is negative numbers count backwords in HEX. See example below.
    decimal 2 = hex: 0000 0002
    decimal 1 = hex: 0000 0001
    decimal 0 = hex: 0000 0000
    decimal -1 = hex: FFFF FFFF
    decimal -2 = hex: FFFF FFFD\
    etc
    So -10 decimal is FFFFFFF6
    LabVIEW can do this easy enough. Make an indicator, right click for properties and change it to HEX display.
    See code below:
    Attachments:
    Hex.vi ‏13 KB

  • Numeric to hex conversion

    Hi
    i am new to labview. i have implemented a controller circuit and serially communicating with using lab view in that i am using a numeric value and converting it to hex using numeric to hex string and receiving that on port 1 of controller but that is displaying ASCII values of my number though i have converted it in hex in block diagram of labview. 
    Attachments:
    serial comm.vi ‏16 KB

    Hi
    I have problem in labview to my hardware communication. when i am using (testing) code for my controller and using CS100FULL.vi then i get whatever data i send on assigned ports. But i want total 12 bit data to deal with and thats to in hex form insted of ASCII so i do the necessary changes in controller code(testing1) and making change in vi also keeping width of decimal to hex string conversion block 3. but i wont get any data at port.
    Please please suggest me whwrw i am making mistakes because in keil this code runs properly and i get at desired data at ports in simulator but when i am loding it in controller it won't work with labview but when i am using hyper terminal it communicate properly and i get data at port 0&1 that
    means i am doing mistake in vi so please suggest me solution and mistakes i am making in my vi.
    Thank you
    Attachments:
    testing.txt ‏2 KB
    testing1.txt ‏1 KB
    CS100Full.vi ‏37 KB

  • Convert Access Module to SQL Function - Hex To Dec conversion

    I need to convert an Access Module to a SQL Function but not sure how to successfully accomplish this.
    The module has several different functions to convert hexadecimal numbers to decimal and vice versa. I am not sure if I needed to break out each module function into a seperate function in SQL or not. Any help would be appreciated.
    Here is the actual module that needs to be converted:
    Public Function MEID_DecToHex(mMEIDDec As String) As String
        'Dim mMEIDDec As String
        Dim mManNum As Double
        Dim mSerialNum As Double
        Dim mMEIDHex As String
        Dim mManHex As String
        Dim mSerialHex As String
        'mMEIDDec = "268435457304109828"
        '*** Check MEID digits, make sure it is 18 digits else return invalid
        If Len(mMEIDDec) = 18 Then
            '*** 18 digit decimal code: 1st 10 digits is for the Manufacturer and last 8 digits is for the Serial Number
            mManNum = Left(mMEIDDec, 10)
            mSerialNum = Right(mMEIDDec, 8)
            '*** Convert MEID Dec to Hex
            mManHex = DecToHex(mManNum)
            mManHex = fntPad(mManHex, "0", 8)
            mSerialHex = DecToHex(mSerialNum)
            mSerialHex = fntPad(mSerialHex, "0", 6)
            MEID_DecToHex = mManHex & mSerialHex
        ElseIf Len(mMEIDDec) = 11 Then
            '*** 11 digit decimal code: 1st 3 digits is for the Manufacturer and last 8 digits is for the Serial Number
            mManNum = Left(mMEIDDec, 3)
            mSerialNum = Right(mMEIDDec, 8)
            '*** Convert MEID Dec to Hex
            mManHex = DecToHex(mManNum)
            mManHex = fntPad(mManHex, "0", 2)
            mSerialHex = DecToHex(mSerialNum)
            mSerialHex = fntPad(mSerialHex, "0", 6)
            MEID_DecToHex = mManHex & mSerialHex
        Else
            MEID_DecToHex = "Invalid"
        End If
    End Function
    Public Function MEID_HexToDec(mMEIDHex As String) As String
        'Dim mMEIDDec As String
        Dim mManNum As String
        Dim mSerialNum As String
        'Dim mMEIDHex As String
        Dim mManDec As String
        Dim mSerialDec As String
        'mMEIDHex = "a000001937b27a"
        ' Remove any spaces befor or after the string
        mMEIDHex = Trim(mMEIDHex)
        '*** Check MEID digits, make sure it is 14 digits else return invalid
        If Len(mMEIDHex) = 14 Then
            '*** 14 hexadecimal digits: 1st 8 digits is for the Manufacturer and last 6 digits is for the Serial Number
            mManNum = Left(mMEIDHex, 8)
            mSerialNum = Right(mMEIDHex, 6)
            '*** Convert MEID Hex to Dec
            mManDec = HexToDec(mManNum)
            mManDec = fntPad(mManDec, "0", 10)
            mSerialDec = HexToDec(mSerialNum)
            mSerialDec = fntPad(mSerialDec, "0", 8)
            MEID_HexToDec = mManDec & mSerialDec
        ElseIf Len(mMEIDHex) = 8 Then
            '*** 8 digit Hex code: 1st 2 digits is for the Manufacturer and last 6 digits is for the Serial Number
            mManNum = Left(mMEIDHex, 2)
            mSerialNum = Right(mMEIDHex, 6)
            '*** Convert MEID Dec to Hex
            mManDec = HexToDec(mManNum)
            mManDec = fntPad(mManDec, "0", 3)
            mSerialDec = HexToDec(mSerialNum)
            mSerialDec = fntPad(mSerialDec, "0", 8)
            MEID_HexToDec = mManDec & mSerialDec
        Else
            MEID_HexToDec = "Invalid"
        End If
    End Function

    Try link
    you can create & use CLR function
    or you can simply convert on fly refer below link
    http://blog.sqlauthority.com/2010/02/01/sql-server-question-how-to-convert-hex-to-decimal/
    http://blog.sqlauthority.com/2012/07/26/sql-server-answer-how-to-convert-hex-to-decimal-or-int/
    decimal to hex
    http://stackoverflow.com/questions/13643729/decimal-to-hex-conversion-in-sql-server-2008

  • Serial comunication and hex

    Hi!
    I am trying to get information from a device that only has one way communication, so I want to sent my device a commando that opens a relay, and then I can measure if the relay is open or not by using the CTS and check for voltage differers. The commando has to be five byte long and in Hex code, I want to read a 16 bit long number. The string constants are known commands and are written in Hex display.
    The attached code doesn't work and I suspect that it is the type conversion to Hex that is causing the problem?
    Solved!
    Go to Solution.
    Attachments:
    VI_hex.png ‏30 KB

    In the middle of your concatenation, you aren't doing a typecast to "hex".  You are taking a number and formatting it to a hex formatted text string.  So if you had the number 16 going in, you are getting 10 out, but that is two characters, a "1" followed by a "0", not a single byte of 10hex.  Or as in your screen shot, the number 15 goes in, comes out as F,  but the character "F" (decimal 71, hex 47) as opposed to a byte of value decimal 15 (a non-printable control code).
    Try byte array to string, or typecast a U8 input to a string.  See this message thread (same as Gerd's above) where the original poster was having a similar problem.
    Message Edited by Ravens Fan on 06-23-2009 10:27 AM

Maybe you are looking for