Converting a binary number to a list of integers

I need to convert a binary number to a list of the values of the bit possitions that make up that number. I.e. 1 = 1; 3=2,1; 7=1,2,4.
Does anyone know of Java API functions that could accomplish this, I couldn't find any, or a function that can do this?

This reminds me of my programming homework assignments...
There are some very efficient ways to do this - but I can't remember them off the top of my head. I can guarantee they will have been posted several hundred times before. This will work:
class BitMask {
    private byte mask = 1;
    public void printBitFields(int a) {
     System.out.print(a + " =");
     for(i = 0 ; (a & Integer.MAX_VALUE) != 0 ; i++) {
         if((a & mask) == 1)
          System.out.print(" " + ((int) java.lang.Math.pow(2,i)));
         a >>= 1;
     System.out.println();
    public final static void main(String args[]) {
     BitMask bm = new BitMask();
     bm.print(1);
     bm.print(18);
     bm.print(19); // etc...
}

Similar Messages

  • Converting a hex number to binary

    How do you convert a hexadecimal number to the actual 1's and 0's of binary? I am using labview 6i. Also I will eventually need the binary to be a string. Thanks.

    Converting for numeric display is quite simple. All you do is on the control/indicator, show the radix, and set it to the desired setting.
    Setting up to display the binary in text is a bit more tricky. You need to insert a "Format Value" function in and wire "%b" to the format string. This will cause the output to change to binary.
    Good luck

  • Converting a binary string to a number...

    Hi guys,
    I'm trying to convert a binary string into a decimal integer. I'm not sure if LabVIEW has a VI that does that. I haven't found one yet. Basically, say I have the string '0101'. I want to convert that to the value '5'. Or say I'm using hex, I want '10101111' to be converted to 'AF'. So that's my dilemma. I'm hoping I'm not going to have to make my own VI. Thanks a lot!
    -Mike

    LabVIEW has exactly what you want even if it can be hard to find it.
    To convert a binary text string like "0101" to a decimal value can easily be done using the Scan Value function found under the String/Number conversion section. If you provide the format %b to it (not mentioned in the manual) you will get the decimal value of your binary string.
    Also, on your front panel you can change the format of your numerical indicators by right clicking on it and selecting Format & Precision. If you have a numerical indicator you can set it do display the numbers in e.g. hexadecimal form.
    However, if you want to convert a number to a hexadecimal text string you can use the Number to Hexadecimal String function also found under the String/Number conversion section.
    I
    attached a simple example, Conversions.vi, that shows how it works. I hope this helps. /Mikael
    Attachments:
    conversions.vi ‏14 KB

  • Is there a way to convert skype online number cont...

    That was the general question, and here are my details:
    I have had a skype number for many years and it was great, around $5.5 a month to call all phones in North America from my laptop from any place in the world with internet. With time, I had a ccumulated a relatively large number of contacts (name of person or party & their phone number(s)). Now I decided that I finally need a regular "smart" cellphone with an AT &T 10c/minute and no data (that's the only way that I understand is not a rip-off, I'm counting on my really unlimited mobile hotspot to get wifi). Now, the company will have me purchase minutes every 30 days which doesn't look very bad considering that I don't have my wifi all the time.
    The problem I'm having is, how to transfer or convert the name/number list on skype to name/number list on my phone? so I can call the same numbers I used to call on slype with my AT&T minutes?
    Typing the numbers one-by-one to my phone may take days!! so, I figured out that there must be away to do it automatically, rather than manually.
    Any help is very appreciated

    Is there any answer skype people?????
    please!

  • About binary number and decimal number?

    how to use a class to convert a decimal number from a binary number?Thank you

    You've already asked the same kind of thing before (http://forum.java.sun.com/thread.jsp?forum=31&thread=325249), and fsato4 answered. Here is the same thing, but decimal to binary.
    public class ToBinary {
         public static void main(String[] args) {
              int n = 12; 
              System.out.println(Integer.toString(n)); 
              System.out.println(Integer.toBinaryString(n));

  • Convert between binary and signed/unsigned decimal numbers

    Hi all,
    Has anyone written a code to convert:
    binary number --> signed decimal
    binary number --> unsiged decimal
    signed decimal --> binary
    unsigned decimal --> binary
    Please help! I'm confusing.

    http://java.sun.com/j2se/1.4/docs/api/java/lang/Integer.html
    See the methods parseInt and toBinaryString.
    Please help! I'm confusing. You are, aren't you?
    (Sorry, couldn't resist...)

  • Need to convert a binary value into decimal

    Hi i need to convert a binary value which i would be getting as a string object to a decimal value......need code for the same

    Check Integer.parseInt
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#parseInt(java.lang.String,%20int)

  • Need to convert the binary data in blob field to readable format

    Hi,
    We need to convert the Binary data in the BLOB field to readable format and need to display it in Oracle Apps Environment,does anybody come across the similar requirement.
    please advise, thanks in advance.
    Regards,
    Babu.

    You could use standard Attachments functionality here ... if the blob is not in FND_LOBS, insert into FND_LOBS, fnd_attached_documents etc to enable viewing via "Attachments" to the entity the blob is related to.
    Gareth

  • How to put a number on reject list from iPhone 4?

    How do I put a number on reject list so when that number calls it does not ring or alert?  Or maybe just go straight to voicemail. 

    That's not a function of your phone. You can contact your carrier and see if they offer blocking features (all do in the U.S.). If it's a specific number you can simply assign a customer ringtone of silence to it.

  • How can I convert the binary file content to XML message

    Dear friends,
    I poll the binary file from a ftp server but the payload only includes the binary content, no XML structure in the payload, I hope to convert the binary content to a element node within the XML structure, how can I do that? via content conversion?
    Thanks and regards,
    Bean

    Read the binary file stream using java I/O standard functions and convert the read stream to Base64 format. Now map this content to one of the field in target XML structure.
    You need a java mapping for this.
    what is your target system?
    Thanks,
    Gujjeti.
    Hi Gujjeti,
    Thanks a lot for your kind help, my target system is R/3.
    Can I achieve that with a UDF or a simple way?
    Regards,
    Bean

  • How to I get the total number of songs listed in my Itunes library to display?

    With recent versions of I Tune intallations I no longer receive the total number of songs listed in my Libary.
    I am using I Tunes v. 11.1.3.8 on windows 7.
    TodonKansas

    CTRL+/ will turn it on.

  • Convert TIF Binary data to PDF Binary data

    Hi All,
    I have uploaded TIF file into table in system in Binary format.
    I need to create a spool from this Binary data, the spool should open in TIF format or PDF format.
    Can you help me in doing this.
    As I knw how to convert PDF to Spool, it would be even helpful, if you tell me how to convert TIF binary data into PDF binay data.
    Thanks in advance.
    Abhay

    Hi Sandra,
    Below is the requirement from Client:
    1. PDF and Tif files will be attached to order (transaction CRMD_ORDER).
    2. I have to pick the PDF and TIF attachments mentioned above using a batch report.
    3. Then this batch report will create a spool for the PDF file and TIF file attachements.
    4. Then the spool will be picked by another program and print them together in night.
    I hope it is clear now?
    Things I have done:
    1. Created report ZPDF_TIF which is copy of RSPO0023.
    1. Used the report ZPDF_TIF to pick up the PDF and TIF file in binary format from the order (transaction CRMD_ORDER).
    2. Able to Convert PDF to spool.
    I hve problem for:
    1. I want to use the program ZPDF_TIF to work for both PDF and TIF file.
    2. I have the TIF data in Binary (1022) into internal table picked using the report ZPDF_TIF.
    2. I want to convert TIF to spool which is problem child for me as of now.
    I hope the details are clear now.

  • Converting a binary string into a JPEG image in Crystal Reports 2008

    Hi Gang
    Iu2019m having problems converting a binary string into an image in Crystal Reports 2008
    I have JPEG images stored in ECC.  ECC stores the data in binary format.
    Iu2019m using the ECC function module SKWF_PHIO_CONTENT_ACCESS_GET to retrieve the data.  This function module has an export table, FILE_CONTENT_BINARY, which returns several lines of data.  Each line contains a maximum of 1,024 characters.
    When I drop the T_ FILE_CONTENT_BINARY.LINE field into my Crystal Report detail section, I wind up with a report that displays all the lines in FILE_CONTENT_BINARY table.  (in my case, 19 lines are displayed.)
    I created a formula to collect all the data into a single string.
    whileprintingrecords;
    stringvar data:= data & {SKWF_PHIO_CONTENT_ACCESS_GET.T_FILE_CONTENT_BINARY.LINE}
    I added the formula to the detail section and itu2019s doing a great job collecting the data.
    I then inserted a picture object in the report footer, opened the format editor, navigated to the u201Cpictureu201D tab, and inserted a formula for the u201Cgraphics locationu201D.
    whileprintingrecords;
    stringvar data:=data;
    data
    My clever idea turned out to be a disappointment . . . . my picture object is blank.
    Does anyone have a solution for converting a binary string into a JPEG image?

    Save the JPEG in a format CR supports. Refer to the help file for the file types.

  • Convert time to number and number to time

    I'm using SAP 4.0b
    I'm looking for function that converts time to number and number to time.
    Any suggestion?

    Hi,
    Can you give an example of what number you want to give to get what time and vice-versa?
    There can be a direct conversion between an integer and a time variable in ABAP.
    For example -
    data: number type i,
          time type syuzeit.
    number = 3600.
    move number to time.
    write time.
    The time will be output as "01:00:00". That is because 3600 seconds make up one hour.
    Regards,
    Anand Mandalika.

  • How to convert exponent to number format

    Hi,
    how to convert exponent to number format.My column is in number and the data is in exponent format .for example  data is 2.44705130197009E18 .when i do field name haveing this data like
    select * from table name where filed name =2.44705130197009E18 ,field name  is of number (20) data type .but i am not getting any data fectched .
    your advice is at most appriciated .
    Regards,
    Suja

    Example of what I was saying...
    SQL> create table myexp (name number);
    Table created.
    SQL> insert into myexp values (2447051301970090001);
    1 row created.
    SQL> select name from myexp;
          NAME
    2.4471E+18
    SQL> col name format 9999999999999999999999999999999999999
    SQL> select name from myexp;
                                      NAME
                       2447051301970090001
    SQL>
    The number you are seeing as an exponent is not just the number that is stored with lots of 0's on it, there's other information you are missing, so you need to change your format to see the true value.

Maybe you are looking for