Working with 'nibbles' in java

Hi, Im storing values in bytes containing two nibbles (4 bits) packed into a vector of bytes. I have two values between 0 and 15 for each nibble, I create two bytes and set each value to these, I then shift the first byte 4 places and and add the result to the second byte to creat the final resulting byte containing two nibbles. Here are two snippets of code from seperate methods:
//to create a byte from two nibbles
//this takes two byte from a vector (in which only the right half has a nibble, the left is 4 zeros: 0000-nibble)
firstHalfByte = ((Byte)(tempResult.get(position))).byteValue();
firstHalfByte = (byte)(firstHalfByte << 4);
secondHalfByte = ((Byte)(tempResult.get(position+1))).byteValue(); //not shifted as above
resultByte = (byte)(firstHalfByte + secondHalfByte);
//to extract nibbles from byte vector
byte firstHalfMask = (byte)11110000;
byte secondHalfMask = (byte)00001111;
currentByte = ((Byte)(v.get(i))).byteValue(); //get byte from vector
firstHalf = (byte)((currentByte * firstHalfMask) >> 4);
secondHalf = (byte)(currentByte * secondHalfMask);
I printed an example out on to the console and got the byte's values
firstHalf: 15
second half: 5
result: -11
In my head it should work out like this:
00001111 (15) 00000101 (5)
11110000 00000101
result: 11110101
when the application attempts to extract the nibbles from -11 it gets
currentByte = -11
firstHalf = -77
secondHalf = -35
If I can somehow make it retrieve 15 and 5 from -11 I'd be very happy. Im guessing its some this to do with the fact that java treats a byte as signed? Surely it should not matter when shifting bits since they're simply binary numbers so it shouldn't matter how java interprets them?
Thanks for your time.

public class Test {
     public static void main(String args[]) {
          byte firstHalf = 15;
          byte secondHalf = 5;
          byte result = (byte)((firstHalf << 4) | secondHalf);
          System.out.println(result);
          firstHalf = (byte)(result & 0xf);
          secondHalf = (byte)((result >> 4) & 0xf);
          System.out.println(firstHalf);
          System.out.println(secondHalf);
}

Similar Messages

  • Does anyone have SSL working with the Sun Java System App Server PE?

    We have been having problems (to say the least) getting SSL to work with the Sun Java Application Server 8.1 Platform Edition.
    We have a signed certificate from VeriSign and have it imported correctly, but when you test it by going to https://localhost:8182/ (note that 8182 is the port set up for SSL) you get a warning mesage saying that the certificate cannot be verified. When you view the certificate you see that it is the one that got automatically generated for you by the app server and not the one we purchased from VeriSign.
    So, I was just wondering if anyone out there has gotten this to work and if so, what document did you follow to tell yoiu how it was done!
    THANK YOU!

    once apon a time i had a real problem with the same issue.. best of luck.. i forget now how to fix.. sorry.

  • Will weblogic 4.5 work with the Sun Java Servlet Development Kit Version 2.1?

              Will weblogic 4.5 work with the Sun Java Servlet Development Kit Version 2.1
              (JSDK 2.1). The reason I want this is we want our application servlets to
              use the new 2.1 redirection mechanism to redirect to JSP files.
              

    WL 4.5 supports JSP 1.0 (and, therefore Servlet 2.1).
              What I want to know is when will it support JSP 1.1 (and, therefore Servlet
              2.2)!
              Regards,
              Murali Krishna Devarakonda
              Cox News <[email protected]> wrote in message
              news:7rk40p$s00$[email protected]..
              >
              > Will weblogic 4.5 work with the Sun Java Servlet Development Kit Version
              2.1
              > (JSDK 2.1). The reason I want this is we want our application servlets to
              > use the new 2.1 redirection mechanism to redirect to JSP files.
              >
              >
              >
              >
              

  • How to work with xml in java ?

    Hello everybody. I am trying to read, write and modify xml file in java. But i don't know what is the best method for work with xml file ? Please give me some examples for read, write and modify it.
    Thanks in advance.

    >
    Hello everybody. I am trying to read, write and modify xml file in java. But i don't know what is the best method for work with xml file ?>'It depends'. I saw some discussions of XML parsing using different J2SE core XML APIs (the J2SE has a selection of ways to deal with XML) where one API was 20 times faster than the other.
    >
    ... Please give me some examples for read, write and modify it. >Please give me a ponie. ;-)
    You will probably need to do a lot of reading, as well as some experimentation, before you decide which XML API is best suited to the particular task you are facing.
    >
    Thanks in advance.>No worries.

  • Work with Files in Java

    Hello!
    Can anyone help me. How can I API in Java Technology for files to find ?

    don't uite understand your question.
    here's the location of java API for File class, for working with File and Directory..
    http://java.sun.com/j2se/1.3/docs/api/java/io/File.html
    for reading and writing..you may want to look at th eio package for classes such as
    Reader, FileReader, BufferedReader, Writer, FileWriter, BufferedWriter
    here's java API
    http://java.sun.com/j2se/1.4.2/docs/api/

  • Why would the Java Plugin not work in Firefox 5 on Mac SnowLeopard? I have the most recent version but am unable to use any Java features on Firefox 5. Firefox 3.6 works with the same Java but 5 will not.

    Most recent version of Java and firefox. Java Applications will start to load but end up in an infinite loading loop.

    Well, it's what I did to get my Java working in Firefox 4. I installed both binaries into my Library/Internet Plug-ins folder. The version was newer that what was previously installed (newer version is 0.9.7.5). It solved the Java problems I was having. My inital problem was that Java would not initiate and no applets would run in Firefox version 4 which I just installed a few days ago.
    I know the readme.txt. says it is not compatible with version 4, but the release date on 0.9.7.5 is after the release date of Firefox 4 and so that was I tried it. I figure there was nothing to lose as at worst it woud update my two plug-in files. Nothing was going to be changed otherwise. If you try it, it might work.

  • Working with CVS and Java Studio Creator 2

    Hello,
    I'm a new user of java studio creator and I would like to make a project using ths CVS.
    First, I've installed a CVS server on a computer.
    Then I've created a new project (an example included with JSC)
    Then I've customized the version manager in JSC 2 to connect to the remote CVS server.
    No problem, if I try to connect to CVS in the version manager, it work ("You are connected").
    On the other hand, when I want to check out my project on the CVS (the first check out), I've got this error :
    cvs server: connect to 82.252.252.173(82.252.252.173):2402 failed: Une tentative de connexion a �chou� car le parti connect� n'a pas r�pondu convenablement au-del� d'une certaine dur�e ou une connexion �tablie a �chou� car l'h�te de connexion n'a pas r�pondu.
    cvs [server aborted]: Couldn't connect to lock server
    Have you got an idea on the configuration error I've done (no solution found in the articles nor faq)?
    Thanks in advance
    Nicolas

    Hello,
    You can see checked out files when you use the Versioning Manager. Just expand the tree to see individual files and folders. It's always a good idea to do an update before you start editing a file in Studio Creator. The Merge Conflict Resolver is a a very useful tool when more than one developer is working on a file.
    You can find a lot more about version control in the IDE's help files.
    And by the way, your English is fine.
    --James                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • What does it take to work with Sun on Java?

    How did they create Java and keep coming out with new versions? Heh, they can't write Java to create it, you know? Or can they? Lets discuss.

    Java Community Process - controls the destiny of the Java platform and is supported and used by all of the major Java vendors and a few independent Java experts.
    www.jcp.org
    Chuck

  • Working with Files in Java

    From my local machine I am running a Java code which fetches values from DB and writes it into a TXT file and save the TXT file into a different server say 'A'. This part is working fine if I run the Java code from my local machine.
    I tried deploying the same Java code into a differnet server say 'B' and executed it, but it failed. The code is trying to save the TXT file into a unknown path which is not specified in the code rather than saving in the server 'A'.
    Please note, Server 'B' is having write access on server 'A' and I have given the absolute path of server 'A' in code.
    Can someone tell me why it is trying to save the TXT file to a path which is not specified in code?
    I am getting the following error message :
    java.io.FileNotFoundException: \\...\...\...(unknown path)
    (Access is denied)
    Plz assist.

    VishnuCBE wrote:
    it is a standalone application and not web based. Servers A and B, you can imagine them as machines connected on network. So in code i am giving the server's absolute path where the file needs to be stored.Please see reply #1. Even if two machines are on a network, it doesn't mean that files can be automagically copied between them. There has to be some way for the file to move through the network across machines. And it's pretty much impossible to tell what's going wrong without some details.
    As i said earlier my problem is, the code is trying to save the txt file in an unknown path which is not mentioned in the code.And a stack trace would help diagnose that.

  • Work with Outlook through Java WebStart?

    I have two questions:
    1. I want my Java app to be able to change stuff in outlook. So when the user uses my app and then opens outlook, it'll be diff. How do I do this?
    2. Is it possible to do the above through Java WebStart? WebStart makes everything over http (i think) or can I also do sockets/SOAP (which yes I know is http, but a bit diff.)? Does anyone know if i can do this?
    Can anyone give me some sample code of even talking to any Microsoft COM through webstart?

    There is a freebie tool we use called bridge2java that makes this fairly easy. You can integrate WebStart as you would with any Java class.

  • Java 7 Update 11 Not Working with Firefox

    For me, the problems described in the thread "Java 7 Update 10 Not Working with Firefox? " Java 7 Update 10 Not Working with Firefox?
    are continuing with Java 7 Update 11.
    Windows 7 64 bit
    Firefox 18
    The problem is that "Java(TM) Platform" is missing from the plug-in list.
    I've uninstalled Java 7 Update 11 and reinstalled Java Update 9 which correctly installs the plugin and restores Java functionality which was broken immediately upon installing both Java 10 & 11.

    981243 wrote:
    So why not using Ju11 ? You can workaround the issue. It would sucks but still be safer than using Ju9.
    Also ask Mozilla forums if Firefox has options where to search for plugins.
    Or try 64-bit Firefox.As I explained in both threads ...
    Java 7 Update 10 Not Working with Firefox?
    Java 7 Update 11 Not Working with Firefox
    ... neither jre7u10 nor jre7u11 are working ... and they are BOTH broken with the same problem ... "Java(TM) Platform" pliugin is missing from the plug-in list. It cannot be enabled, because it simply is NOT there. A suggestion was made the jre7u12 will be the "fix" for this issue ... so I installed the Update 12 Preview and it sis ALSO broken, no "Java(TM) Platform" in the plug-in list.
    The ONLY Java version that actually works for me is jre7u9.
    As far as installing Firefox 64bit ... I see no future in installing a browser that has been discontinued.
    http://www.computerworld.com/s/article/9233976/Mozilla_suspends_work_on_64_bit_Firefox_for_Windows
    Even though Mozilla relented due to backlash, I continued development will be a somewhat low priority.
    http://www.computerworld.com/s/article/9234997/Mozilla_compromises_on_x64_Firefox_after_user_backlash

  • Working with .pdf files and JAVA

    Hi,
    does anyone have an answer to how I can find more information on .pdf files?
    I would like to convert .pdf files to textfiles and/or xml files. I can not find it in the j2se Edition, and someone told me it can be found in the j2ee edition, but I can not find anything there either. Please help..
    thanks,
    R.

    thanks for your reply. What tools do you mean? I know lots of tools for converting text to a .pdf file, but no tools for the other direction. There is an API available (commercial), that lets you work with PDF in JAVA, but i am interesting in the other possibilities.
    Regards

  • Quick time not work with java programming

    I'm student and I want to use java .
    but it don't work with quick time .
    java can't run if I have quick time in my computer .
    (It works if I uninstall quick time)
    And how can I use iTunes without quicktime Or how can I
    fix that problem .
    Some one pls. HALP ME!!!!!
    Notebook   Windows XP Pro  

    Help Apple, Please!!!!
    I have still this problem!
    If I install QuickTime (7.0.3) all Java applications will not run.
    It works if I uninstall QuickTime...!
    Please help!
    Thanks

  • Issuse with WebDynpro iViews - Java or ABAP

    We frequently get calls from users who complain that they can't see a screen in the portal, and it is usually because they have accidentally collapsed an iView.
    The problem we have found is that it doesn't seem to work with WebDynpro iViews - Java or ABAP.

    Rohit,
    You can also hide the tray display on you portal by setting the iView property "Show Tray"  to "Yes".
    Ram

  • Probleme with versions of java

    I've copmiled my Applet with java
    1.3.1_16 but doesn't work with the 1.3.1_01 version

    What else did you expect? You can't expect that your applet works with all older java versions... And what is the problem???
    Thea

Maybe you are looking for