Printing hexadecimal/binary numbers

I'm trying to print the hexadecimal and binary representation of the following:
public static void main(String[] args) {
int t = 0x1;
t = t<<30;
System.out.println(0xt);
I tried to print the hexadecimal representation of t using the above, but it didn't work (I know t isn't a hex number, but I want the contents of variable t printed in hex). How can I accomplish this?
Thanks ahead.

Use the Integer class. It has methods for binary and hex:
Integer.toBinaryString(int i);
Integer.toHexString(int i);

Similar Messages

  • Printing Binary Numbers in SP

    I am trying to print binary numbers in my output.
    Below is the expected output
    1 0x5F6AB40860296D4DB07C346FA12E25FD
    2 0x5F6AB40860296D4DB07C346FA12E25FD
    Below is the output i am getting
    -1590811137
    CREATE
    TABLE Testbinary(
    [ID] [int]
    NOT
    NULL,
    [yVolumeUnitID] [binary]
    (16)
    NOT
    NULL
    insert
    into Testbinary
    values(1,0x5F6AB40860296D4DB07C346FA12E25FD)
    insert
    into Testbinary
    values(2,0x5F6AB40860296D4DB07C346FA12E25FD)
    select
    from Testbinary
    delete Testbinary
    select yVolumeUnitID
    from dbo.MdPriceDesc
    alter
    proc vol
    as
    declare
    @ID
    int,
    @VolumeID
    binary(16),
    @out
    varchar(100)
    begin
    select @ID=ID,
    @VolumeID=yVolumeUnitID
    from Testbinary
    set
    @out = @ID+''+@VolumeID
    print
    (@out)
    end
    exec vol

    You have some implicit conversion going on. Your INT column is ADDED to your VARBINARY column by 
    @out = @ID+''+@VolumeID
    DECLARE @table TABLE (id INT, number VARBINARY(MAX))
    INSERT INTO @table (id, number) VALUES
    (1, 0x5F6AB40860296D4DB07C346FA12E25FD),
    (2, 0x5F6AB40860296D4DB07C346FA12E25FD)
    declare @vb VARBINARY(MAX), @int INT
    SELECT @vb = number, @int = id
    FROM @table
    PRINT @vb
    PRINT @int+@vb
    PRINT CAST(@int AS NVARCHAR)+''+master.sys.fn_varbintohexstr(@vb)
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

  • Binary numbers to decimal numbers

    Hello, Im writing a program that changes binary numbers to decimal numbers. I seem to be having a probelm calculating the last number in the binary code and adding it to the total. Also, when I use large binary numbers the output isnt anywhere near correct. help? please? thank you

    public class binarynumbers
    public static void main (String [] args)
    int decimal=0;
    Scanner scan= new Scanner(System.in);
    System.out.print("enter binary number> ");
    String bin=scan.next();
    int zero=0;
    int one=1;
    int length=bin.length();
    int newlen=length-1;
    while (newlen>=0)
         String number = bin.substring( zero , one );
         int number1=Integer.parseInt(number);
         int squareRoot=Math.pow(2,newlen);
         decimal+=(squareRoot*number1);
         newlen--;
         zero++;
         one++;
    System.out.println("The decimal number translation is " + decimal);
    i did that but the math part isnt working and im getting a message like this
    binarynumbers.java:26: possible loss of precision
    found : double
    required: int
         int squareRoot=Math.pow(2,newlen);
    ^
    1 error

  • Recursion with binary numbers

    I need to print out a list of all possiblle binary numbers with as many digits as an int k. For example, if k = 3, it would need to print out 000,001,010,011,100,101,110,111. for k = 2 it is only 00, 01, 10, 11. It is pretty clear that for any k, a recursive technique can be used to solve this problem, but I'm having trouble finding the solution. Please help. Thanks

    You don't need recursion:for (int i = 0, max = 1 << (k - 1); i < max; ++i) {
      print binary i to k digits
    }But a recursive approach would be void increment (int[] data, int digit) {
    if (digit > 0) {
    --digit;
    for (int i = 0; i < 2; ++i) {
      data[digit] = i;
      increment(data, digit);
    } else {
    print contents of data array
    start (int k) { increment(new int[k], k); }Neither code tested.
    Pete

  • Operations on very large binary numbers

    Hi guys,
    I'm trying to write a java class for manipulations of very large binary numbers.
    I'm representing the BN internally as boolean[] (array of booleans false for 0 & true for 1).
    I want to write an algorithm for the following operations :
    shifLeft (boolean[] b,int n) : shifting binary number to left by n positions.preferably a circular shift .
    and also the corresponding shiftRight() method.
    can some one guide me on how to implement this ?
    thanks.

    Consider an array of ascii chars....
    array =>   | |a|b|c|d|
    offset = 1
    len = 4In the above there are actually five spots in the
    array but the offset points to the second position in
    the array and the length is 4.
    If I was to extract the value it would be "abcd"
    because of the offset and the length.
    Now a 'shift right' means that if it is "abcd" then
    it should now be "abc" (because the d fell off the
    end.)
    I can do that like this.
    array =>   | |a|b|c|d|
    offset = 1
    len = 3Notice in the above that nothing changed except the
    length. But because the length changed if I
    extracted the value I would get "abc" because the
    offset is 1 and the length is three.
    Notice also that there was no array copying.Are you sure shifting works like that ?
    what I know about left shifting is that the 'd' should be moved left -toghether with a, b, c- and we append a 0 in place of 'd' .
    from what you said the 'd' would be gone , or am I again wrong ?
    it seems i still didn't get any satisfactory answer to this problem...

  • Anyone know of a way to adjust the top and side MARGINS of a document printed from iOS numbers? The default margins are too wide. Need more working space.

    Anyone know of a way to adjust the top and side MARGINS of a document printed from iOS numbers? The default margins are too wide. Need more working space.

    Open the document,
    Tap the Tools icon (upper right).
    Tap Document Set up.
    Drag the margins to the position you wish (the actual margin width sould display as you are doing this).

  • Print View in Numbers 3.0

    I Need to see the print view in numbers 3.0. No longer an option under "view" tab. Also the page view I'm given does not align with the preview page when actually go to print - they look different and neither has transfered my document the same from previous numbers document.

    Thats it I have spent alot of time trying to re format my reports from the older version of numbers to the new, I thought for a little while I could live without the page view as i spent alot of time lining up the gold lines as page breaks but now I for some reason cant find the photos I want to use they are only listed by their date and when used in the spreadsheet, they are not where they should be when printing, Im sorry for using this forum for venting but I am absolutely P.....ed off the amount of time I have spent for nothing.  I have really apple and speak very highly of them, and I just cant believe they could update a programme like this, did they even test it before they put out there.  What the F is going on. sorry but Im NOT HAPPY, I think I will now go back to excell definately.

  • Printing: print prepared binary stream with SAPWIN

    Hi .
    We have a lot of different documents(MS Word, MS Excel, TIFF, PDF etc.) stored in DMS.
    Now we need to print them from SAP applications using SAP printers.
    For that we have an external conversion server, that could convert files to any print stream data (PCL, PLC2, PCL5, Postscript, even simple PDF).
    If I use printer with simple device type (e.g. Sapscript driver is HP LaserJet PCL4/PCL5) , I just convert necessary docs into the PCL output, create programmatically a new Spool request with format G_RAW and BIN content and add PCL output to it. And this way works good. But not with SAPWIN device type.
    Does anybody know, if it's possible to print prepared binary stream (PCL, Postscript or other format) using printer with SAPWIN device type? And if yes, how should I create Spool request?
    Thanks in advance.

    Sorry for this up.
    But we still have the problem.
    Any ideas?

  • How can I print comments in Numbers? I think was announced in the new features...

    How can I print comments in Numbers in the desktopt version? I think was announced in the new features but I can't see it.

    Add comments using the button in the toolbar:

  • How do i get the line/row numbers to print on my numbers document?

    how do i get the row/line numbers to print on my numbers spreadsheet?

    Neil,
    You could make a Screen Shot with a cell selected so that the Row and Column tabs are active. That's a poor way to go about it though since the result will be a graphic with rather low resolution.
    Better to make some labels yourself and add them to the Sheet before printing. You can use single row/column tables for this, or Text Boxes.
    Jerry

  • How do I set the print area in Numbers?

    How do I set the print area in Numbers?

    Hi Macuser4ever,
    Numbers does not have the 'Set Print Area' feature. Numbers is designed around several tables, each with a purpose. For example, Input Table, Big Database, Intermediate Calculations Table (all of which you may not need to print) and a final Summary (Presentation) Table that you may wish to print. The Summary Table can be on its own Sheet. Arrange objects (Summary Table, Charts [graphs] and whatever) on one Sheet and print only that Sheet.
    If you are using Numbers 3.x (Layout View and Print View missing) try this User Tip:
    Print Layout Guide for Mac Numbers 3.2
    Regards,
    Ian.

  • Compare 2 Binary Numbers

    Hi all ,
    suppose I have two arbitrary lenght binary numbers (could be very large binaries).
    exple : 1000111 & 11111110001
    is it possible to compare them using only there 0s & 1s representations.
    i.e I don't want to convert them to base 10 & compare them (probably using BigInteger).
    what I'm looking for is an algorithm that compares 1000111 & 11111110001 only using there 0s & 1s sequences.
    If this is possible how can I implement it ?
    many thanks.

    boolean equal = true;
    for(inti = ar1.length, j=ar2.lenght; i >= 0 && j
    =
    0; i--, j--) {
    if(ar1[ i ]!=ar2[j]) {
    equal = false;
    break;
    } this code will tell you if ar1 & ar2 are equal but
    won't tell you if ar1 <ar2 or ar1>ar2
    how can we tell ar1 > ar2 for exple ?oh my bad.
    well then indeed one would hav to start at the highest bit and embed the "shorter" value with 0's.
    if the representation is in a primitive, eg. long, you cant simply write a < b since java doesnt know unsigned numbers. so either you are carefull enough and only store 31 bits in an int(like leave the highest bit alone) or you check the highest bit first, and then check the remaining.

  • Adding binary numbers in java please help!!

    Hello all, im a total newbie to java and i need your help urgently, i have two variables
    that are integers, that store binary numbers i.e.
    int tmpIntOne, tmpIntTwo;
    tmpIntOne = 1010;
    tmpIntTwo = 1110;
    i want to add these numbers together and return a binary result so far when you add them together you get:
    2120
    however i would like a binary result so that
    result = tmpIntOne + tmpIntTwo;
    = 11000
    Thank you.

    Hello all, im a total newbie to java and i need your
    help urgently, i have two variables
    that are integers, that store binary numbers i.e.
    int tmpIntOne, tmpIntTwo;
    tmpIntOne = 1010;
    tmpIntTwo = 1110;These are not binary numbers. These are decimal numbers whose digits consist of ones and zeros. If you want to interpret the characters "010" as a binary number, then do
    int tmp1 = Integer.parseInt("1010", 2);
    etc.
    i want to add these numbers together
    int result = tmp1 + tmp;
    and return a
    binary result Adding two ints will give an int. Int's are always binary. If you want to display it as a binary String, as opposed to the usual decimal String, then, as suggested, use toBinaryString.

  • SQL Query to print 1-n numbers?

    for(int i =0; i<n i++)
    We can print 1-n numbers on the console by using above loop.
    In the sameway How I can display 1-n numbers on SQL console by using SQL Query..?
    Can any body help me regarding this?>

    SowmyRaj wrote:
    hi justin.... thanks for ur answer.... can u give me ur yahoo or gmail id?Now, i'm really stunned by your so many rapid posted threads and that too you can do yourself if you invested some time and make some R&D work.
    I don't want to hurt your feeling but i think you should invest some time to do this job. Or, you can get plenty of related solution and then you have to customize those to your required solution. Only that will help you to earn knowledge.
    You know one general suggestion -> Try to do the solution by yourself. If you stuck or don't have any clue then post it here - we will post the clue or post your required solution if you stuck.
    We are always there to help you. Don't mind.
    Regards.
    Satyaki De.

  • Set margins, add footer to printed pages in Numbers 3?

    How do I set top, bottom & side margins & add a header and/or footer with such things as filename & date to printed pages in Numbers 3?  This capability was available in previous versions, & is available with the "Setup" icon in Pages.  (This icon is missing in Numbers 3)

    BW,
    Apple thought you might not miss Page Headers and Footers if they left it out of the new version.
    You can go back to Numbers 2.3 or you can use Pages 5.0 for your publication after doing your calculations in Numbers.
    Jerry

Maybe you are looking for

  • How do i save attachments in photo gallery?

    i"ve been trying to save attachments sent from a mobile phone to my documents or photo gallery. the ones i've saved i couldn't open and the rest i couldn't save

  • Titlebar in Acrobat 9 Pro disappears when window moved.

    I have a client who is using Acrobat Pro 9.0 in a Windows 7 64-bit environment.  He is also using two monitors and can move documents between them. If his PDF is open and maximized and he drags and moves it to the other monitor without placing it at

  • How to implement ajax at ADF table column or ADF table column button.

    I want to use ajax in table column selection. I have two table. One is master table and second one is detailed table. I have requirement to click master table column and display data in detail table column against the master table column. let assume

  • Interview question being asked

    Hi All, I was asked interview techinical question. I was not able to answer these. can anyone tell me what are the answers for these! Q How do you convert Basic cubes to Transactional Cubes? Q Diffrence between version Bw3.5 with other older version

  • Is there a default for text size

    Text size varies between 12pt and about 8pt - there does not seem tro be any logic that determines which. Size can be adjusted using CTL/+/- but you don't want to do this on every other page.