How do Bitwise Operators work?

Hi everybody
I know a little bit of bitwise operators and I am getting some problems working with them.
For example, imagine the byte 0x42 (Or 01000010). Now I want to build a long having this byte on the first position starting from the left so I try the following code:
long l = 0x42 << 56;However, this operation seems to work like if I have written:
long l = 0x42 << 24That is, the new long is a String of only 32 bits. Why does this command ignore the first 32 bits? Any ideas?

> On a small tangent, I asked this question yesterday:
what does this program output?
Guess, then copy and run to see if you were right.
public class PartyPretzel {
public static void main(String[] args) {
System.out.println(12345 + 5432ll);
Wauu. I would have bet my hand saying that the result will be 66666 and it is 17777. And the reason for this is....

Similar Messages

  • How do Shift Operators work?

    Pls I am just beginning to write simple programs in java,
    and would like to know how precisely shift operators
    (e.g >> << >>>) work.
    Thank you in anticipation.

    I am a student, and have read my notes yet could not be
    clear about the shift operators actually work (function).
    Pls assist!Here's a start:
    Compile and run the following line:System.out.println("33 << 4 == "+(33 << 4));which should print something like this:33 << 4 == 528Now, if you write down the binary representations of the numbers 33 and 528, you'll get: 33 == 00000000 00000000 00000000 00100001
    528 == 00000000 00000000 00000010 00010000 Do you now see how the 4 is related to the operation?

  • Using bitwise operators

    hi,
    I'm new to java.. Still learning ....I hope some one would help me here ...
    I wanted to check how bitwise operator works... tried all operators .. but the NOT operator seems to work in a different way ..could someone brief me ...
    ~2 -2
    but the program gives a result -3.
    pls explain how it works

    It reverses all the bits in the number, that is: 0 becomes 1 and 1 becomes 0. And because the "two's complement"-rule defines negative numbers as "-x" = ~x + 1, you get ~x = -(x+1). 2 = 0000 0000 0000 0000 0000 0000 0000 0010
    ~2 = 1111 1111 1111 1111 1111 1111 1111 1101
       = -(0000 0000 0000 0000 0000 0000 0000 0010 + 1)
       = -3

  • Using bitwise operators to swap individual bits

    I'm able to set or clear individual bits using masks, however I'm trying to figure out how I could go about swapping two bits using bitwise operators but I haven't been able to figure it out. For example, say I had int x = 37 which is 100101 in binary and I wanted to swap the 2nd and 3rd bits I'd like to get 100011 when I use Integer.toBinaryString(x) after performing some bitwise operations on x to swap bits around. Any suggestions ?

    How about something like this? A preliminary test seemed to work.
    class BitSwap2 {
      public static void main(String[] argv) {
        int x = 37;
        System.out.printf("Binary: %s\n", Integer.toBinaryString(x));
        swapBits(x, 2, 3);
      private static void swapBits(int x, int a, int b) {
        if(a == b) {
          System.out.printf("Nothing to swap.\n");
          return;
        int first = (x & (1<<(a-1)));
        int second = (x & (1<<(b-1)));
        // zero them out from the original so that we can swap them
        x ^= (first | second);
        if(a > b) {
          int diff = (a - b);
          x |= (first >> diff);
          x |= (second << diff);
        } else {
          int diff = (b - a);
          x |= (second >> diff);
          x |= (second << diff);
        System.out.printf("Binary: %s\n", Integer.toBinaryString(x));
    }

  • Bitwise Operators .. stupid question ?

    I have a HashMap which contains Strings.. The String are actually numbers.
    I want to use Bitwise operators of and or, xor on them... How so I do it?
    I want to say result = string1 and string2...... I am not sure how stupid this sounds... but I am sure I am too close to it....

    Example answer to your original question, wanna:
    Hashtable<Object, String> ht = new Hashtable<Object, String>();
    ht.put("twenty eight", "28");
    ht.put("five", "5");
    ht.put("twenty", "20");
    System.out.println(Integer.valueOf(ht.get("twenty eight")) & Integer.valueOf(ht.get("five")) & Integer.valueOf(ht.get("twenty")));Which, of course, prints "4" to standard out. You're best off using a Hashtable<Object, Integer>, though.
    In answer to your second question,
    ~ is indeed the compliment operator. E.g:
    System.out.println(1 + ", " + (~1));
    prints "1, -2", as you might expect.

  • How can I transfer work from one computer to another?

    How can I transfer work from one computer to another?

    Welcome to the forum.
    I can think of three basic ways to accomplish what you wish to do:
    Use the Project Archiver to archive your Project (and check the box to gather the media files), to an external HDD. Probably the easiest way to do it.
    Copy the Project and ALL media files to an external HDD, but be prepared to relink the media files to the Project, as the drive letter (part of the Absolute Path) will have changed.
    Edit loosely, and Share to an AV file, which will be Imported into a New Project on that second computer. Or, edit VERY tightly, and do the same. I like the first, as removing, replacing Transitions, etc., can be much more difficult, unless that "tight edit" is 100% done.
    Good luck,
    Hunt
    Message was edited by: Bill Hunt to correct formatting

  • How export to csv work in safari browser? In my application export to csv open like a raw data in new tab. But other browsers working great!. Need to open in a csv file or save it as a csv file.

    How export to csv work in safari browser?
    In my application export to csv open like a raw data in new tab.
    But other browsers working great!.
    Need to open in a csv file or save it as a csv file.
    Please suggest me. Thank you in advance!.

    Hi Adrian,
    Why don't you try any another software for opening CSV files then Notepad ? According to my experience, you can use these softwares to open an CSV files and they are:-
    Microsoft Excel
    Open Office Calc
    Google Docs
    Also there is an additional tool available known as CSV viewer. You may try this, download it from here http://www.csvviewer.com/
    I've never used Notepad for opening CSV files, because sometimes it contains some symbols which are not not at all compatibile with Notepad.
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • How enter prise search works in sharepoint 2010

    In my organization enterprise search is configured ,
    -- sharepoint farm has
    -- two index servers ( share point server search  service is  configured in this servers)
    two web front end servers(sharepoint foundation web applications, and  share point server search  service is  configured in this servers)
    - two  application servers( central admin service is running)
    - one sql server
    here i am new to this area
    here how entr prise search works,  why index servers used
    index data stored sepratly in thi servers?
    and when user query for any documentid where it will search initially
    i know the concept of search there are 3 things
    1) query
    2)index
    3)crawler
    adil

    Hi,
    In Microsoft SharePoint Server 2010 Search, index partitions are groups of query components, each of which holds a subset of the full text index and which return search results to the query originator. Each index partition is associated with a specific property
    database containing metadata associated with a specific set of crawled content.
    The index server manages the crawling and indexing of SharePoint Server content and maintains the index file. The index service works with the query service to let you search SharePoint Server content.
    Every SharePoint Server deployment must have at least one index server. Additional index servers may be necessary as the deployment grows. There can only be one index server per server farm.
    If you use the web front end as your query server.  This tells the index server to propagate its index to the WFEs that are set as query servers so that they have a local copy of the index.
    When someone does a search (this is done on the WFE), then that WFE will search itself locally instead of going across the network to query the index server.  
    This increases speed at the time of query, but it of course introduces additional overhead in terms of having multiple full copies of the index on the network and the network demand of propagating those index copies all the time. 
    If you select the query role on your index server, then the index will not get propagated and all searches will query the index server across the network.  
    For more information, you can refer to the following article.
    http://www.sharepointpitstop.com/2012/08/sharepointsearch-index-query-crawl.html
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Macbook pro to HDTV, video is working but audio is not working, how to make audio work as well

    Macbook pro to HDTV, video is working but audio is not working, how to make audio work as well

    If you use an HDMI cable, the audiostream will be integrated, so there will be sound when using an HDMI cable!
    Not necessarily.  That only works as stated if you have one of the most recent MBP's that has a built-in HDMI port.
    If the MBP only has a Thunderbolt or miniDisplayPort, you need an appropriate adapter cable and even if you use an HDMI adapter or cable to connect to your HDTV there is no guarantee it will carry audio.  You have to determine if your specific MBP model supports audio out through its miniDisplayPort or Thunderbolt output, and whether the adapter does likewise.

  • How do you connect your photoshop elements on your computer to your account online? and how do you create a customized url? how does the gallery work and how do you access it? i have trouble signing in on my program from my computer to connect to the onli

    how do you connect your photoshop elements on your computer to your account online? and how do you create a customized url? how does the gallery work and how do you access it? i have trouble signing in on my program from my computer to connect to the online photoshop, and I really want to create my own customized url and post photos to my gallery and share them with the world, family, and friends, but i need help because i can't figure how to do any of this, would really appreciate feedback and assistance, thanks, - claire conlon

    To add to sig's reply, "calibrating" does not calibrate Lithiu-Ion batteries, it calibrates the charge reporting circuitry.  If you look at the effect of deep discharging Lithium-Ion batteries in the data from the independent test group, Battery University, you will see that doing so shortens the life of the battery significantly. It looks like an optimum balance between use and life is at a discharge level of 50%.

  • How can two users work on iMovie?  My husband is working on a memorial video for a family member who passed, I plan to edit but he had to take his computer to work.  I have the iMovie project on a zip drive.  How do I get it to open in my imovie?

    How can two users work on iMovie?  My husband is working on a memorial video for a family member who passed, I plan to edit but he had to take his computer to work.  I have the iMovie project on a zip drive.  How do I get it to open in my imovie? 

    You will need an external drive that is formatted as MAC OS EXTENDED (journaled).
    Move the Project, Events, and any photos and music to the external drive by following the instructions in this post.
    https://discussions.apple.com/docs/DOC-4141
    Be sure to use CONSOLIDATE MEDIA to get the photos and music. Then plug this drive into your computer and you will be able to edit.

  • Does anyone know how the cutout filter works and is there a way of achieving the same effect without using filters to get more control over final look?

    does anyone know how the cutout filter works and is there a way of achieving the same effect without using filters to get more control over final look?

    Several ways to get similar results.  Image > Adjustments > Posturize with low values similar to what you'd use n Cutout.  This is the most flexible way I can think of as you keep the image in RGB mode with layers intact.  A more radical approach would be to reduce bit depth using Indexed Colour.  You'll need to experiment with settings, try changing Forced to Primaries, and Matte to Foreground Color.  There's no going back from this route, although you can change the mode back to RGB to re-enable layers, adjustment layers etc.
    A nice thing about the Filter gallery filters is that you can change the layer to a Smart object with all the control that gives you.
    Now if only this forum could filter out bizarre content.

  • Is there a way to know how many hours of work did a project demanded ?

    Is there a way to know how many hours of work did a project demanded (even if it was on multiple days, sessions or cross-working other projects)?
    I am using Adobe Premiere Pro CS6 on windows 7.
    Thaks,
    Mihai

    There is no feature for that in Premiere Pro.  I suggest that you keep a project log either in a spreadsheet, database, Notepad or Wordpad file, or a hand written one.
    You can file a feature request here:
    Adobe - Feature Request/Bug Report Form

  • How Do Mobile Codes Work? FAQ

    You may have seen them in our weekly ads, on BestBuy.com, or on signs in our retail stores: two-dimensional images that look similar to traditional bar codes, but are irregular and often square. Ever wonder what they are? They’re Mobile Codes!
    What is a Mobile Code?
    A Mobile Code is any two-dimensional (DataMatrix or QR code) or linear bar code (UPC) which can be read by a smart phone, linking the physical world with the on-line world. Some bar code symbologies are in the public domain, such as UPC and DataMatrix and some symbologies are proprietary (e.g. Microsoft’s Tag and EZ codes).  Bar Code scanners today are “image scanners,” and since most smart phones have cameras built into them, we can now use them as personal bar code scanners!
    Do I need software to read a Mobile Code?
    Yes. The Best Buy Mobile App is free software you can download to your phone that contains a bar code reader. The reader will scan UPC and QR codes for products carried by Best Buy. To download the reader, simply follow these instructions:
    1)      Text “APP” to 332211.
    2)      Click on the link that is returned
    3)      Download and install the Best Buy Mobile App on your phone
    4)      Launch the app, push the Product Scan button, and hover the phone over the code.
    Try this one: 
    You can also download the app through several platform-specific app stores:
             iPhone via Apple App Store
             Android Phone via Google Play
             Windows Phone and Touch Screen PC via Windows Phone Store
    Additional app features can be found on http://www.BestBuy.com/App.
    What phones are supported?
    The Best Buy Mobile App is available on most iPhone, Android, and Windows Mobile devices. It is also available for Touch Screen PCs. iPad version coming soon!
    What service plans will I need?
    The service relies on a data plan from your provider or the free Wi-Fi network available in each of our retail stores. The amount of bandwidth consumed varies based on the product experience rendered. If you do not have an unlimited data plan, please plan accordingly. Remember, watching videos can use more bandwidth than viewing mobile web pages.
    What type of bar codes can I scan with the Best Buy Mobile App?
    The Best Buy Mobile App reads QR (Quick Response) Codes, which are the square two-dimensional bar codes with the three smaller squares in the upper right and left of the bar code and in the lower left.   The Best Buy Mobile App can also read UPC codes (the codes used at cash registers in stores). The app does not currently read Data Matrix codes which are square two-dimensional codes, but they don’t have the three smaller squares in them.
    What will happen when I scan the Mobile Code?
    After reading a Best Buy Mobile Code, you will be taken to a mobile web page that contains item specific information. You can use the Best Buy Mobile App to compare a number of products or narrow your selection of items based on parameters you select while in the store.
    Is there any personal information involved?
    No personal information is obtained from your phone. If you have the Best Buy Mobile App and have logged in, your My Best Buy membership information may be used to create a personalized experience.
    How do mobile codes work?
    The Best Buy Mobile App includes the software required to turn your phone into a scanner. All you need to do is initiate the scanner and hover the phone over the code. The app scans the code and launches the corresponding experience. It’s the best of both worlds: you can be online and in the store at the same time!
    How do I save the data for use later?
    On the iPhone and Android, add the product to your cart. Products added to your cart are available until removed. A list of recently viewed products can also be accessed through the main app menu.
    What prices will I see on my mobile device?
    You will see our regular BestBuy.com prices.  In some cases they may vary from the in-store price.

    If you touch the left side of the telephone number field, you get a drop down Label from which you can select the type of number it is to be.

  • TS2634 I bought a composite AV cable with 30 pin connector at a proper apple store for my ipad 2 which no longer works now i have updated to ios7 - please advise how to make this work ?

    I bought a composite AV cable with 30 pin connector at a proper apple store for my ipad 2 which no longer works now i have updated to ios7 - please advise how to make this work ?

    I have the same problem.
    Two similar discussions:
    https://discussions.apple.com/message/23081658#23081658
    https://discussions.apple.com/message/23281391#23281391
    I have not yet seen any official response to the question: "Is the Apple AV Composite cable fully supported with 30pin connector devices upgraded with iOS7 - specifically ? - eg. iPad 2, iPhone 4, iPhone 4s"
    If it is not currently supported is that then due to a bug / oversight and in that case is it something that will be fixed in the near future?
    Please let us know what feedback you got from asking Apple support.

Maybe you are looking for

  • HT201317 how can I add multiple photos to camera roll

    how can I add multiple photos to camera roll

  • Possible fix to Battery Update 1.3 issue?

    So I installed the battery update 1.3 on my MBP, and like many of you guys, promptly got my battery health / life wiped by about half (242 cycles, capacity before and after update was about 4700 and 2600, respectively). I tried resetting the SMC and

  • Adapter Class not formed error in bdk 1.1. with jdk1.4.2

    Hi, i have installed j2sdk 1.4.2 on my machine n bdk 1.1 now I have set classpath apropriatly.now when i m going to hook up two beans there appear this error WARNING: Could not Runtime.exec(String) "javac" in the standard way: java.io.IOException: Cr

  • Uploading data in to standard SOP?????

    Hi Gurus, we are using standard SOP for planning the forecast of all the FG materials using MC87. The issue is we are entering each material data manually in MC87 and then checking the rough cut capacity. Please guide me any solution to upload the fo

  • Program too large error

    Hello Friends I am using oracle forms 6. I write code on button's WHEN-BUTTON-PRESSED event and then compile that trigger at that time i am getting error "program too large" Ofcourse on that event coding is large but what i have to do to avoid that c