Converting from decimal to binary to hexadecimal to octal

hello everyone,
my question is, Is there a way to get decimal input from user and print the binary, hexadecimal and octal value of that decimal? just like C does in printf command

http://java.sun.com/j2se/1.3/docs/api/java/lang/Integer.html

Similar Messages

  • I want to convert from decimal (5, 2) to decimal (3,0) in data services

    Hi All,
    I want to convert from decimal (5, 2) to decimal (3,0) in data services.
    if anybody knows please let me know with syntax.

    https://scn.sap.com/community/data-services/blog/2013/06/12/conversion-functions-in-bods-with-examplespart3
    https://scn.sap.com/community/data-services/blog/2013/06/12/conversion-function-in-bods-with-examplespart3

  • Do anyone know how to convert a decimal to binary, 1 into 01

    do anyone know how to convert a decimal to binary
    i wants to convert 1 into 01, but the computer print out 1, it didn't print 0
    also 0 it also print only 0, and 3 it print11
    so decimal of 3, the computer print correct, but 0 and 1 it print wrong
    how can i print 01 if my decimal is 1
    int a=1;
    System.out.print(Integer.toBinaryString(a));
    can anyone help me solve this question
    and
    you can use java or jsp
    if you can use jsp it would be better, if not use java

    it's not printing anything 'wrong'.
    0 in binary is 0
    1 in binary is 1
    All it's doing is cutting off leading zeros since they don't change the value.
    1 is the same as 01 is the same as 00000001...no difference
    Similarly, when you print decimal 3 as 11, it could just as easily say 00000011 and be correct, since the zeros don't change anything.

  • Convertion from Decimal to Hexadecimal

    Hi,
    Can you please tell me the way to covert a given decimal number into hexadecimal (for example 4 -> 04, 20 -> 14 etc) and also the vice versa.
    thank you.

    Hi
    Try this function module:
    " CRM_EI_KB_CONV_DEC_TO_HEX "
    This fm converts any decimal to hexadecimal, but not vice-versa.........
    Hope it helps....

  • Conversion from decimal to binary!

    int i=1234;How can I convert an integer to its binary form??

    int i = 1234;
    String binInt = Integer.toBinaryString(i);

  • Converting from binary to decimal

    i writ this program to let the user input his number and then it will be converted to decimal,but how can i limited the rang of my digit,or if i want him to enter 4 digits only what can i do,,,and if i dont limit a range how can i make it?

    this is my code
    import javax.swing.JOptionPane;
    public class Ch4_25
    public static void main(String[]arg)
         int F,d1,d2,d3,d4,num=1;
         String N = JOptionPane.showInputDialog("Enter the number");
         num=Integer.parseInt(N);
         d1=num/10000;
         num=num%10000;
         d2=num/1000;
         num=num%1000;
         d3=num/100;
         num=num%100;
         d4=num/10;
         F= d4*1+d3*2+d3*4+d2*8+d1*16;
         JOptionPane.showMessageDialog(null,"the number is"+F);
         System.exit(0);
    }     

  • Convert decimal to binary

    hi all!
    I want to convert from message box witch is in ascii (decimal) to a signal in binary... can anyone help me?
    thanks in advance

    hello,
    I've made this example. It's strange. But in the moment it's my only idea.
    it output's two different ways. Because I didn't understand exactly what you need.
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Convert.vi ‏10 KB

  • Convert from Comma notation to Decimal Notation, Any FM ?

    Hi Experts,
    I am looking to convert from Europe format to US format for Quantity & amount fields, I mean
    e.g. Europe:  12.3456,78 -> US: 12,3456.78
    pls. i can not use offsetting, replace, pattern, overlay, concatenate etc.
    So, pls. let me know that, Is there any SAP FM for this purpose of DECIMAL NOTATION conversion?
    thanq
    Edited by: Srinivas on Feb 22, 2008 10:48 PM

    use.
    Replace all occurances of ',' in w_value with '.'.
    Check this thread.
    REgarding converting  ','  TO  '.'

  • How to convert numeric data to binary decimal in java

    How to convert numeric data to binary decimal in java Pleas egive me code example

    There is no numeric data. It's all binary. If you're talking about Strings, look at the Integer class.

  • Convert Binary to Hexadecimal

    Hi,
    Can anyone show me how do I convert Binary to Hexadecimal ?
    Thank you,
    Any help will be appreciated.

    Well, everything is stored in binary on computers so your explanation of the problem sucks big time, however maybe you want something like this.
    String binString = "101001010101101";
    String hexString = Integer.toHexString(Integer.parseInt(binString, 2));

  • Hi I would like to know if you can convert decimal to binary using actionscript 3.0?

    Hi I would like to know if you can convert decimal to binary using actionscript 3.0?

    Hi thanks for the response Ive tried to implement the code as you stated but it is not outputting please if you could check the following code and let me know where Ive gone wrong that would be much appreciated Thanks!.
    miles_txt.addEventListener(KeyboardEvent.KEY_DOWN,convertKilometres);
    miles_txt.restrict ="0-9";
    function convertKilometres (k:KeyboardEvent):void {
    var miles:Number;
    var kilometres:Number;
    if (k.keyCode == Keyboard.ENTER){
    miles=Number(miles_txt.text);
    kilometres=miles* 1.609344;
    kilometres_txt.text = kilometres.toPrecision(2);
    kilometreConvert_txt.addEventListener(KeyboardEvent.KEY_DOWN,convertKiloToMile);
    kilometreConvert_txt.restrict = "0-9";
    function convertKiloToMile(k:KeyboardEvent):void{
    var kilometreConvert:Number;
    var milesAnswer:Number;
    if (k.keyCode==Keyboard.ENTER) {
    kilometreConvert=Number(kilometreConvert_txt.text);
    milesAnswer=kilometreConvert* 0.621371192;
    milesAnswer_txt.text = milesAnswer.toPrecision(2);
    binary_txt.addEventListener(KeyboardEvent.KEY_DOWN, checkEnterKey2);
    function checkEnterKey2(e:KeyboardEvent):void{
    if(binary_txt.text != '' && e.keyCode == Keyboard.ENTER){
    decimal_txt.text=binaryToDecimal(binary_txt.text).toString();
    function binaryToDecimal(s:String):Number{
    var n:Number = 0
    for(var i:int=0;i<s.length;i++){
    n+=Number(s.substr(i,1))<<(s.length-1-i)
    return n;
    function decimalToBinary(n:Number):String{
    return n.toString(2);
    return_btn.addEventListener(MouseEvent.CLICK, goBackToCalculator);
    function goBackToCalculator(e:Event):void
    mybuttonSound.play();
    gotoAndStop("Calculator");
    clear_btn.addEventListener(MouseEvent.CLICK,clearField);
    function clearField(e:MouseEvent):void{
      mybuttonSound.play();
      miles_txt.text ="";
      kilometres_txt.text ="";
      milesAnswer_txt.text ="";
      kilometreConvert_txt.text ="";
      binary_txt.text ="";
      decimal_txt.text ="";

  • Convert decimal to binary with a fixed length

    Hi, I need to write a program that converts a decimal number to binary with a fixed length (say 5), for example, decimal digit "0" -> binary number "00000". I try Integer.toBinaryString(), but it will just cut off the leading bits, so I wonder how to let the conversion happen, anyone can help me with that, thanks in advance.
    mckie

    Daiyue_Weng wrote:
    Hi, I need to write a program that converts a decimal number to binary with a fixed length (say 5), for example, decimal digit "0" -> binary number "00000". I try Integer.toBinaryString(), but it will just cut off the leading bits, so I wonder how to let the conversion happen, anyone can help me with that, thanks in advance.
    mckieWhat do you expect it to do? When you limit yourself to 5 digits binary you can only represent 0 to 63 and you will loose anything not in those 5 digits.

  • Is it possible to convert ascii data in binary?

    Hi all.
    In my one table there is a column which contains ascii value. i want to convert it in binary. It it possible in oracle?
    eg field value:1250ÿ it should be 125011111111
    kindly tell how to do this.
    i have tried this using a simple java program but doesnot work for some ascii values.
    thank you

    I created two functions :
    create or replace FUNCTION dec2bin (N IN NUMBER) RETURN VARCHAR2 IS
    binval VARCHAR2(64);
    N2 NUMBER := N;
    BEGIN
    WHILE ( N2 > 0 ) LOOP
    binval := MOD(N2, 2) || binval;
    N2 := TRUNC( N2 / 2 );
    END LOOP;
    RETURN binval;
    END dec2bin;
    And other :
    create or replace function to_ascii( inSource IN VARCHAR2 )
    return varchar2 AS
    ResultString varchar2(381); -- 3 * possible length of source
    TempNumber number;
    begin
    for i in 1..length( inSource ) loop
    TempNumber := dec2bin ( ascii( substr( inSource,i,1 ) ) );
    ResultString := ResultString || trim( to_char(TempNumber,'00000009'));
    end loop;
    return ResultString;
    end;
    Now, in sqlplus : (just to show the binary string)
    column mybin for 9999999999999999999999999999999999999999
    SQL> select to_ascii('g') mybin from dual;
    MYBIN
    01100111
    SQL> select to_ascii('girish') mybin from dual;
    MYBIN
    011001110110100101110010011010010111001101101000
    SQL>Source:http://psoug.org/snippet/Convert-between-Decimal-Binary-Octal-and-Hex_536.htm
    http://www.dbforums.com/oracle/974944-converting-string-binary.html
    Is this you want or something else ?
    Regards
    Girish Sharma

  • Convert from String to Int

    Hi,
    I have a question.
    How do I convert from String to Integer?
    Here is my code:
    try{
    String s="000111010101001101101010";
    int q=Integer.parseInt(s);
    answerStr = String.valueOf(q);
    catch (NumberFormatException e)
    answerStr="Error";
    but, everytime when i run the code, i always get the ERROR.
    is the value that i got, cannot be converted to int?
    i've done the same thing in c, and its working fine.
    thanks..

    6kyAngel wrote:
    actually it convert the string value into decimal value.In fact what it does is convert the (binary) string into an integer value. It's the String representation of integer quantities that have a base (two, ten, hex etc): the quantities themselves don't have a base.
    To take an integer quantity (in the form of an int) and convert it to a binary String, use the handy toString() method in the Integer class - like your other conversion, use the one that takes a radix argument.

  • Decimal to binary conversion script

    hi
    i m very happy to all of u on ur response
    i m really happy with this forum
    i need a script to convert the decimal number in to binary
    number
    83---------->1010011
    thx

    here are two handlers I picked up from James Newton. I
    couldn't find them anywhere on his site (
    http://nonlinear.openspark.com)
    so I paste them directly here.
    credits go to James.
    on mMakeRuleMap(anInteger)
    -- INPUT: <anInteger> must be an integer
    -- OUTPUT: Returns a 32-item list of 0s and 1s corresponding
    to the
    -- binary representation of anInteger
    if anInteger < 0 then
    tBinary = mMakeRuleMap(the maxInteger + 1 + anInteger)
    tBinary[1] = 1
    else
    tBinary = []
    tBits = 32
    tBinary[32] = 0
    repeat while anInteger
    tBinary[tBits] = anInteger mod 2
    anInteger = anInteger / 2
    tBits = tBits - 1
    end repeat
    end if
    return tBinary
    end mMakeRuleMap
    on mBinaryToDecimal(aBitList)
    -- INPUT: <aBitList> is a list of 0s and 1s (up to 32
    items)
    -- OUTPUT: a decimal number corresponding to the binary
    number
    -- defined by <aBitList>
    tBitValue = 1
    tDecimal = 0
    i = aBitList.count
    if i = 32 then
    if aBitList[1] = 1 then
    -- The number is negative
    i = 31
    tDecimal = the maxInteger + 1
    end if
    end if
    repeat while i
    if aBitList
    then
    tDecimal = tDecimal + tBitValue
    end if
    tBitValue = tBitValue * 2
    i = i - 1
    end repeat
    return tDecimal
    end mBinaryToDecimal

Maybe you are looking for