My mask doesn't work for reading bits

the following table represents a stream of bits. within the bits are certain fields that i need to be able to read, and extract. I tried writing code to do pretty much exactly what I need, but the mask isn't working. here is the exact situation of what I have:
| 15 | 14 | 13| 12| 11| 10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|-----------------Word Count--------------------------------------| word 1
| 0- | 1-- |-------------Message_ID------|----unused---------| word 2
|---------------------stuff I don't care about here -------------| word 3
| --------------- more stuff I don't care about here ---------| word 4
My goal in writing this code was to extract the Message_ID and put it in its own file. to do that I wrote code to skip the first word (which is two bytes) and read the second word after shifting the Message_ID to the far right (at least thats what I thought the coding would do :) Again, thank you for all your guys' help
well here is the short java file that I wrote, its not long so please look at it and tell me why it wont mask and shift the Message_ID and write it into a new file
import java.io.*;
public class Mask {
public static void main(String[] arguments) {
try {
// create object to be read
File bits = new File("c:/test.txt");
FileInputStream file = new FileInputStream(bits);
//skip the first two bytes
file.skip(2);
//read the next two bytes
byte[] ary = new byte[2];
//read file that contains bits
file.read(ary);
//create a mask
int i = 0;
int messageIDBits = (i >> 6) & 0xFF;
//create object to write the bits which were read
File txt = new File("c:/test1.txt");
FileOutputStream messageID = new FileOutputStream(txt);
//write the bits containing the Message_ID
messageID.write(ary);
//close the files
file.close();
messageID.close();
} catch (Exception e) {
System.out.println("Error -- " + e.toString());
}

Sorry it took so long - had a meeting. Here's the demo. Run it, study it, and let me know if you have any questions:import java.io.*;
import java.util.*;
class BytesDemo {
    private static Random rand = new Random();
    public static void main(String[] args) {
        new BytesDemo().go();
    void go() {
        byte[] testBytes = new byte[2];
        rand.nextBytes(testBytes);
        System.out.println("Here are our starting bytes (" +
                            testBytes[0] + ", " +
                            testBytes[1] + "):");
        System.out.println(toBinary(testBytes[0], 8) +
                         " " +
                         toBinary(testBytes[1], 8));
        System.out.println("\nNow, we'll call the getMessageId() method...");
        int messageId = getMessageId(testBytes);
        System.out.println("\nOur final message ID is: \n" + messageId);
        System.out.println("\nAnd here's the short version: " + getId(testBytes));
    int getMessageId(byte[] b) {
        if (b.length != 2) throw new IllegalArgumentException("I need two bytes!");
        System.out.println("\nFirst, we'll create the word.");
        System.out.println("Here is the first byte, shifted to the left: \n" +
                           toBinary(b[0] << 8, 16));
        System.out.println("\nHere is the second byte, kept as it is: \n" +
                           toBinary(b[1] & 0xFF, 16));
        System.out.println("\nNow we will OR the two together...");
        int word = (b[0] << 8) | (b[1] & 0xFF);
        System.out.println("...resulting in the word: \n" + toBinary(word, 16));
        System.out.println("\nThe first 6 bits aren't needed, so we'll shift the word:");
        word = word >> 6;
        System.out.println(toBinary(word, 16));
        int mask = 0xFF;
        System.out.println("\nOur mask looks like this: \n" + toBinary(mask, 16));
        System.out.println("\nSo now, we'll AND the shifted word and the mask together...");
        int messageId = word & mask;
        System.out.println(toBinary(messageId, 8));
        return messageId;
    int getId(byte[] b) {
        if (b.length != 2) throw new IllegalArgumentException("I need two bytes!");
        int word = (b[0] << 8) | (b[1] & 0xFF);
        return (word >> 6) & 0xFF;
    String toBinary(int num, int bits) {
        StringBuffer buf = new StringBuffer(Integer.toBinaryString(num));
        int len = buf.length();
        if (len > bits) buf.delete(0, len - bits);
        while (len++ < bits) {
            buf.insert(0, "0");
        return buf.toString();
}

Similar Messages

  • VS2013 edit-and-continue doesn't work for 32-bit (error 1006)

    Microsoft Visual Studio Professional 2013, Version 12.0.30501.00 Update 2, is running under 64-bit Win7. App is 32-bit debug build, C++ (native).
    When at a breakpoint, if I change the source code and continue, I get a message
    Edit and Continue : error 1006 : A global or static variable was added, renamed, removed, or changed data type or initialization: ___ImageBase (referenced by: c:\MyProgram\debug\MySource.obj)
    This occurs no matter what the change. In the example above, I added 1 character to the end of a comment line.
    Both edit-and-continue and native edit and continue are enabled (screen shot below).

    Hi VoiceOfExperience,
    Maybe you could share us a simple sample, so we could test in the same Environment.
    After you enable the edit and continue, please restart your VS, test it again.
    In addition, you know that there are some limitations for VC++ with it.
    See:
    http://msdn.microsoft.com/en-us/library/0dbey757.aspx , so we could make sure that it doesn't go against thses rules.
    Maybe you could test it in other VS machine, if we make sure that it really meets the requirements as the above link, but it still has this issue, maybe you could submit a report here:http://connect.microsoft.com/VisualStudio/feedback/CreateFeedback.aspx,
    you'd better share a simple sample in your report, so it would be helpful for the product team expert to repro/troubleshoot this issue.
    Have a nice weekend,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can I add a new Template to My Templates in Pages? I've read most of the discussions on the subject but it doesn't work for me. By the time I reach the Templates folder, I only see templates for Numbers and not for Pages. Need help, please.  Thanks

    How can I add a new Template to My Templates in Pages? I've read most of the discussions on the subject but it doesn't work for me. By the time I reach the Templates folder, I only see templates for Numbers and not for Pages. Need help, please.  Thanks

    Si vous avez utilisé la commande Save As Template depuis Pages, il y a forcément un dossier
    iWork > Pages
    contenant Templates > My Templates
    comme il y a un dossier
    iWork > Numbers
    contenant Templates > My Templates
    Depuis le Finder, tapez cmd + f
    puis configurez la recherche comme sur cette recopie d'écran.
    puis lancez la recherche.
    Ainsi, vous allez trouver vos modèles personnalisés dans leur dossier.
    Chez moi, il y en a une kyrielle en dehors des dossiers standards parce que je renomme wxcvb.template quasiment tous mes documents Pages et wxcvb.nmbtemplate à peu près tous mes documents Numbers.
    Ainsi, quand je travaille sur un document, je ne suis pas ralenti par Autosave.
    Désolé mais je ne répondrai plus avant demain.
    Pour moi il est temps de dormir.
    Yvan KOENIG (VALLAURIS, France)  mercredi 23 janvier 2011 22:39:28
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • Web Dynpro dropdown doesn't work for Adobe Reader 8

    Hi All,
    I've developed a Web Dynpro project which uses Interactive form.
    The form has a dropdown (simple type from WDJ).
    The dropdown works for Adobe Reader 7 but doesn't work for Adobe Reader 8 (when I press the arrow to open the list nothing happens).
    Do I need to config/install something for supporting Adobe Reader 8?
    I'm using J2EE 7.13.
    Thanks,
    Omri

    Dear Omri,
    Make sure that you are using Adobe Reader 8.1.1.
    Thanks and Regards,
    Anto.

  • [kde] "Only show tasks from the current desktop" doesn't work for max

    Hi,
    I have two monitor setup (laptop + main monitor) and I would love to use "Only show tasks from the current desktop" option in KDE Task Manager but for some strange reason it doesn't work for me. Well, it works but only partially - for restored/unmaximized windows. When I maximize one it appears on the Taskbar on both screens. Is this normal? May it be due to the fact that I've placed Taskbar on top of the screens?

    Did you miss this bit
    "Graphics : 1 GB NVIDIA Quadro 600 (1DP & 1DVI-I) (1DP-DVI & 1DVI-VGA adapter) (ELGA13) 1"
    And the final image clearly states the type of Graphics Card he has
    Photoshop CS6 GPU FAQ
    Tested video cards for Photoshop CS6
    Adobe tested the following video cards before the release of Photoshop CS6. This document lists the video card by series. The minimum amount of RAM supported on video cards for Photoshop CS6 is 256 MB. Photoshop 13.1 cannot display 3D features if you have less than 512 MB of VRAM on your video card.
    Important: This document is updated as newly released cards are tested. However, Adobe cannot test all cards in a timely manner. If a video card is not listed here, but was released after May 2012, you can assume that the card will work with Photoshop CS6.
    Adobe tested laptop and desktop versions of the following cards. Be sure to download the latest driver for your specific model. (Laptop and desktop versions have slightly different names.)
    nVidia GeForce 8000, 9000, 100, 200, 300, 400, 500, 600 series
    nVidia Quadro 400, 600, 2000, 4000 (Mac & Win), CX, 5000, 6000, K600, K2000, K4000, K5000 (Windows & Mac OS)

  • Static text as mask doesn't work

    I'm creating a button that uses static text as both content
    and as a
    mask (to create an inner shadow effect). The static text is
    in a
    symbol. It looks perfect in the IDE, but when I test the
    movie or
    publish it, the mask doesn't work. I originally had the text
    in a
    graphic symbol and that caused the mask to be completely
    ignored. I
    changed the symbol to a MovieClip, and that behaves
    differently. The
    mask is no longer ignored, but now the mask layer itself
    appears and
    covers up the other layers.
    I've googled for this problem and have seen many comments
    about it. The
    typical solutions seem to be to convert the text to a symbol
    (already
    done) and use static text (already done). Yet it still
    doesn't work.
    I'm using Flash MX 2004.
    Please help. Thanks.

    apply it with actionscript,
    make your text a movieclip and give it a name like "textClip"
    then
    make your mask a movieclip and give it an instance name like
    "textMask" and use this code
    textClip.setMask(textMask);
    to disable the mask with actionscript use:
    textClip.setMask(null);
    good luck!

  • The wifi at my school isn't very good. And I can't send iMessages through it. It works for some apps like score center and my radar app, but doesn't work for other apps like clash of clans and iMessage. How can I get it to work on that  wifi network

    The wifi at my school isn't very good. And I can't send iMessages through it. It works for some apps like score center and my radar app, but doesn't work for other apps like clash of clans and iMessage. How can I get it to work on my school wifi. I have an iPhone 4S on AT&T and iOS 7.04

    In a roaming network, your "main" router is the device that would require port mapping/forwarding to be configured in order to access the IP camera from the Internet. This router is also the one that would be provide the private IP address for the camera which you will want to be a static one.
    So as you described your network, the IP cameras should be getting an IP address or you assigned it a static one and this is the address that you would enter in the Private IP address (or equivalent depending on the router used) field when setting up port mapping.
    If you are not able to access this camera from the local network, then this should be troubleshot first.

  • With my i phone 4 , the Push notifications doesn't work for apps like (fb viber , whatsapp etc ) it only works for the official apps like message  even when im using the phone, has  this probleme with the iOs 6.0.1 and also with the iOs 6.1

    With my i phone 4 , the Push notifications doesn't work for apps like (fb viber , whatsapp etc ) it only works for the official apps like message  even when im using the phone, has  this probleme with the iOs 6.0.1 and also with the iOs 6.1

    This isn't an issue. Notice the screen prior to the one that shows usage has an iCloud section and a Manage Storage button. For this button to activate ios needs to download a few kb from icloud. Switching back to this screen forces ios to download those few kb.

  • Push notifications doesn't work for apps like (fb viber , whatsapp etc ) iOs 6.1

    With my i phone 4 , the Push notifications doesn't work for apps like (fb viber , whatsapp etc ) it only works for the official apps like message  even when im using the phone, has  this probleme with the iOs 6.0.1 and also with the iOs 6.1

    Sorry, I've forgotten the actions done.
    I've restarted the iphone, and I've recovered a previous backup.
    Thanks.

  • Apache Sling JCR Resource Resolver doesn't work for the anchor tags which is been rendered through j

    Certainly I realized that Apache Sling JCR Resource Resolver doesn't work for the anchor tags which is been rendered through jquery or javascript.
    e.g.
    In Felix Console , in Apache Sling JCR Resource Resolver configuration I have added following mapping.
    /content/myproject/-/
    So If any anchor tag is there like <a href="/content/myproject/en.html"> click me </a> then it will be mapped to "/en.html" automatically.
    But the problem is there in following scenario.
    I have an anchor tag as follows.
    <a href="#" id="test"> click here </a>
    And I am assigning the href to anchor through JQUERY.
    <script>
    $("#test").attr("href","/content/myproject/en.html");
    </script>
    Ideally this should have been mapped to "/en.html".
    But it is not mapping to "/en.html". It still shows "/content/myproject/en.html".
    How to resolve this.
    Thanks,
    Sai

    In a servlet you have access to the resourceResolver so if you know which attributes contain links then it's relatively easy to apply resourceResolver.map to those links.
    Your challenge is clearly how do you know which attributes are links and which aren't. Its is the same challenge that makes parsing the response and rewriting it on the way out difficult - the JSON doesn't have any semantic meaning so how do identify which attributes require rewriting. There really is no good answer ot that question in my experience - all the options have down sides.
    Create some convention - all attributes matching this pattern X get mapped before being converted to JSON (could be attributes whose name ends in link, or it could a convention applied to the value of the attribute - if the attribute is a string that starts with /content apply the resource resolver mapping. In this case you have train your developers to follow this convention which is the down side.
    Create some configurable list of attribute names that require mapping. This is brittle, requires training and is easy to break.
    Implement a client side version of the resource resolver mapping. It wouldn't be as full proof as server side mapping (because that takes into account but you could make it work for simple logic like stripping of /content/site/en. If ou are just trying to solve the simple version of this issue - stripping off the top of the repository path this might be your best option.
    Not worry about it and set up Apache 301 redirects that catch any long URLs and redirect them to short URLs (so configure apache to look for any URL matching /content/site/en and strip off /content/site/en and do a 301 redirect to the shortened URL. You end up with a lot of extra HTTP request because of all the 301s but it would work (I wouldn't recommend this option - but it is possible).

  • HT201263 Unable to update, restore or recover. Slider doesn't slide and number pad doesn't work for passcode. What next? Worked last night . Battery charged. When I push Home button I get my backgroung but can't slide slider. Device is recognized by iTune

    Unable to update, restore or recover. Slider doesn't slide and number pad doesn't work for passcode. What next? Worked last night . Battery charged. When I push Home button I get my backgroung but can't slide slider. Device is recognized by iTunes.Help! Thank you.

    Besweet, I'm having the very same problem with 60GB colour which was bought new and worked for 6 months before suddenly just not being recognised by PC. I hadn't changed anything at all.
    I've followed all troubleshooting advice and reinstalled and updated iTunes and iPod updater software but all troubleshooting routes seem to hit the dead end of either the need to access the iPod via the PC (which isn't possible as it's not showing up at all) or the iPod in disc mode stuck at "ok to disconnect".
    It's still under 1yr warranty so will have to take to a dealer.
    I'm sorry that's not much help for you but at least you know it's not a unique problem.
    PC   Windows XP  

  • How do I uninstall Firefox 4 & get previous version back? The new upgrade has problems & doesn't work for me.

    How do I uninstall Firefox 4 and get the previous version back?
    The upgrade has many problems and doesn't work for me.

    new version is the worst Firefox ever, no lip.

  • Oracle client 9i doesn't work for windows ordinary user

    Hello All,
    I've installed oracle 9i client on windows xp. Client software works for user belonging to windows administrators group. it doesn't works for ordinary users not belonging to administrators group. Particularly when i run sqlplus from command line i get following error :
    Incorrect environment variable PLUS_DFLT
    Program execution error.
    i also need access to Oracle ODBC driver.
    When i try to configure ODBC source (created by user with administrator privileges) by common user i get following errors :
    The setup routines for Oracle for Oracle in OraHome9i ODBC driver couldn't be loaded due to system error code 5
    Could not load the setup or translator library
    Very appreciate for any help.
    Regards Arkadiusz Masny

    It sounds like the users on the machine do not have access to the Oracle home directory. Check the permissions of the folder by right properties, select the user and check that they have read and then select advanced. Tick the "replace permission entries....." box and apply. This will re apply all user rights in all folders and subfolders. Try again.
    HTH Mark F

  • "Move Current Track Automation Data to Region" doesn't work for all

    I have been using the 'Move Current Track Automation Data to Region' and while it works fine for some types of automation data like channel volume, pan and some plugin parameters, it doesn't work for all of them.
    I haven't done exhaustive research into which parameters work and which don't, but most of the parameters for individual voices within Ultrabeat don't - which is annoying as that is what I was trying to use it for.
    Any ideas about this, or workarounds?

    OK, well an update on this in case anyone's interested.
    With some further experimentation I have discovered that this problem did not exist in Logic 7 - ie you can move current track automation data for individual Ultrabeat voices to the region.
    It's also possible to move automation data for individual Ultrabeat voices using 'Move All Track Automation Data to Region,' so I suppose this is a kind of workaround, though it can be annoying if you don't want to move all track automation data.
    I'm now assuming this is a bug in Logic 8; is there any way to convert a Logic 8 project to work in Logic 7, as this along with the touch tracks bug is making working in Logic 8 very frustrating?

  • Previously posted troubleshooting doesn't work for my error message "iTunes could not back up the iPhone because an error occurred".  What other options do I have?

    Previously posted troubleshooting doesn't work for my error message "iTunes could not back up the iPhone because an error occured".  What other options do I have to backup my iPhone data properly?

    Hi there kchagape,
    You may find the troubleshooting steps in the article below helpful.
    iOS: Troubleshooting backup issues in iTunes
    http://support.apple.com/kb/ts2529
    -Griff W. 

Maybe you are looking for

  • Mac Backup on Windows Server (Wildcard issues)

    So our Art department is suppose to be backing up all files to a Windows Server. Which brings this problem. Of course being designers we use wildcard symbols on naming files which the windows server won't allow. So when we attempt to backup, the copy

  • How can I add the Blackberry my friend gave me to my account that already has my prepaid phone on it?

    How can I add the Blackberry my friend gave me to my account that already has my prepaid phone on it?

  • Safari Mail Password question

    Hello, I am new to the mac world and got a macbook (not pro) for xmas. Everything appears to be ok but I have a question regarding the mail option. I believe I have leopard because I use safari to hit the web but Im not sure. If someone could verify

  • Average quantity for Prior weeks

    Hello Friends, I have a requirement to calculate prior 4 weeks quantity average and price average. And also I have to calculate price variance by substracting current weeks price with previous weeks price. I have price and quantity are in KF, and cal

  • Solaris 10 scripts in /etc/rc2.d at boot time

    On Solaris 8, boot our scripts in /etc/rc2.d displayed echo to the console and allowed "read" from the console. In Solaris 10, the input/output from our scripts goes to msglog. How can I get these scripts to send output and receive input to the conso