Convert byte to bits, can it be done in Java?

I'm working on a compression program for class, and I'm wondering how I can convert a byte to the bits it is represented by. Does anybody know if you can do this in Java?

I don't think that's what I'm looking for. What I
want is the 1s and 0s representation of the character
A, B, and so on.Characters in Java are represented by the 16 bit Unicode. Each character has been assigned a 16 bit number according to the code charts here,
http://www.unicode.org/
For example a latin 'A' is represented by the number 65,
char c = 'A'; // bit pattern 1000001
int i = c;       // same bit pattern 1000001
System.out.println(c + " = " + i);The above prints the 'A' both as a character and as a number. In both cases it's the same bit pattern 1000001. To extract the bit pattern you can loop 16 times and utilize the following bitwise operations,
   if ((i&1) == 1) // Rightmost bit in i is a 1 (set)
   i = i >> 1; The bit pattern in i is shifted one bit position to the right

Similar Messages

  • Is there an easier way to convert bytes into bit(boolean) arrays?

    I am currently using this method to convert bytes into bit arrays:
    /*convert byte to int such that it is between 0-255 this is the bytes[] array
                        if ((bytes/128)==1)
                             bit[c+0]=true;
                        else
                             bit[c+0]=false;
                        if ((bytes[i]-bitInt[c+0]*128)/64==1)
                             bit[c+1]=true;
                        else
                             bit[c+1]= false;
                        if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64)/32==1)
                             bit[c+2]=true;
                        else
                             bit[c+2]= false;
                        if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32)/16==1)
                             bit[c+3]=true;
                        else
                             bit[c+3]= false;
                        if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32-bitInt[c+3]*16)/8==1)
                             bit[c+4]=true;
                        else
                             bit[c+4]= false;
                        if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32-bitInt[c+3]*16-bitInt[c+4]*8)/4==1)
                             bit[c+5]=true;
                        else
                             bit[c+5]= false;
                        if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32-bitInt[c+3]*16-bitInt[c+4]*8-bitInt[c+5]*4)/2==1)
                             bit[c+6]=true;
                        else
                             bit[c+6]= false;
                        if ((bytes[i]-bitInt[c+0]*128-bitInt[c+1]*64-bitInt[c+2]*32-bitInt[c+3]*16-bitInt[c+4]*8-bitInt[c+5]*4-bitInt[c+6]*2)==1)
                             bit[c+7]=true;
                        else
                             bit[c+7]= false;

    You can loop through and use a bitwise operator instead. Here is an example without the loop.
    byte b = 6 ;
    if( b & Math.pow( 2, 0 ) == Math.pow( 2, 0 ) ) ;
    // the 2^0 bit is on
    if( b & Math.pow( 2, 1 ) == Math.pow( 2, 1 ) ) ;
    // the 2^1 bit is onetc...
    You should get something like 110 when you're done.
    If you're wonder what & does (no, its not a boolean &&), it takes the bits in the two numbers you give it and returns a number with all the bits on that are on for each of them.
    For example:
    10011011 &
    11001101 =
    10001001
    So if we take
    110 (6) &
    010 (2^1, or 2) =
    010 (2 again)
    Which means that the number (6) has the 2^1 bit on.

  • It can be done in C++, can it be done in Java?

    Hi
    In C++, the following code will change a to 2.
    int a = 1;
    int *b = &a;
        *b = 2;How can this be done in Java?
    My reason is that I implemented SortedSet so that it creates and maintains a binary tree (Assignment pre-requisite).
    If the subSet method is called, it returns a portion of the Tree!
    How can i get it to return this portion so that any changes which are made to this subSet are automatically reflected in the original Tree? (Just trying to be a geek and get extra brownie points)
    Thanx
    Tecknick

    public class MyInt {
    public int sss;
    public MyInt myInt = null; // only reference
    public MyInt( ){
    } // default constructor
    } // class MyInt ends here..
    // here now..
    public MyInt a = new MyInt( );
    a.myInt = a; // very Clever
    a.sss = 1; // Your ---------------> int a = 1;
    public MyInt b = a.myInt; // your
    ------------------> *b = &a;
    b.sss = 2; // Your -----------------> *b = 2;
    What is the point of the member field myInt here? The example code gives the effect of just using MyInt myInt = this; and not setting the value in the client code. Why would you ever need to explicitely give an object a reference to itself? You would get exactly the same results (and clearer code) if it wasn't present:
    public class MyInt {
      public int value;
      public MyInt(int value) {
        this.value = value;
      public static void main(String[] argv) {
        MyInt a = new MyInt(1);
        a.value = 1;
        MyInt b = a;
        b.value = 2; //Since a == b, a.value is now equal to 2 as well.
    }Notice that this is now the same idea as was posted by rabbit3000 earlier - it just doesn't use accessor methods (up to you if you decide you want to) - all it is, is a mutable version ot java.lang.Integer. I couldn't see a good reason for a default constructor, so I took that out too.

  • Can it be done in java?

    hi,
    i am doing a project in which the following needs to be done:
    i have a set of map files with me. now in my project, i need to create a frame with an icon. when i click on the icon, i should get a window that should allow me to choose any one of the map files that i already have.
    can this be done in java or is it easier to implement it in java script? i will appreciate if any of u can suggest me the exact procedure to follow preferably using java.

    Yes it can be done in java. If you want to do it as applcation then there is no problem. But if you want to write an applet then the applet should be signed.
    the way is, create a button with a image. handle the buttons action event and in that display filedialog box to select the file.
    Thanks
    Regards
    vivek

  • Can this be done in java? i think so  but how?

    Hello,
    I just wanted to know how to add icons to a JDesktopPane like the appear on your desktop, that's whatever OS you use, I've looked everywhere and cant find the answer, posted this question here several times still no answer. Is it that nobody knows how to do this or it's it cant be done in java?????? ANYONE!!!

    Hi there
    Now this is not perfect
    You cannot press the duke
    to move around him you have to miss him to do that
    So it needs improvment
    but its a start
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MainPanel extends JDesktopPane implements MouseMotionListener,MouseListener
         private JLabel test;
         public MainPanel()
              test = new JLabel(new ImageIcon("duke.gif"));
              test.addMouseListener(this);
              this.addMouseMotionListener(this);
              test.setBounds(50,50,50,100);          
              this.add(test,new Integer (10));          
         public void mouseDragged(MouseEvent e)
              Point p = e.getPoint();
              test.setLocation(p);
         public void mouseMoved(MouseEvent e){}
         public void mouseClicked(MouseEvent e)
              if(e.getClickCount()==2)
                   System.out.println("You double clicked me");
         public void mousePressed(MouseEvent e){}
         public void mouseEntered(MouseEvent e){}
         public void mouseReleased(MouseEvent e){}
         public void mouseExited(MouseEvent e){}
    }/Markus
    PS every thing can be done In java

  • Voice Recognition security System... Can it be done with Java??

    i'm working in graduation project and i'm developing a system that use voice Recognition security System [the user voice as ID] so i'm asking if it can be done with java and if any tutorials about it ??
    null

    Make the PDF file available as a normal URL on the server.
    Redirect the client browser to the URL.
    This will work IF Acrobat is installed, AND is installed as a plugin to the browser, but that's a reasonable assumption if you're presenting PDF files in the first place.
    I wouldn't personally be inclined to try to do this with an applet (JSPs + Servlets would be the way to go in my opinion), but it may be possible to redirect the page from an applet...?

  • Is this can only be done through Java mapping?

    Hi Friends,
    my scenario is jdbc to idoc.
    Am able to create multiple idocs basing upon delivery_date. But here my requirement is -- there are qty, slnumber, vaxinum are having different values. And all these should also be generated in the same Idoc.
    INPUT
    delivery_date         ------      qty   -------- slnumber        -------- vaxinum
    19/02/2006            ------  10      ----------   457854        --------- 10001
    19/02/2006            ------  20      ----------   457855        --------- 10001
    19/02/2006            ------  30      ----------   457854        --------- 10001
    19/02/2004            ------  20      ----------   457854        --------- 10001
    19/02/2004            ------  20      ----------   457854        --------- 10001
    19/02/2005            ------  20      ----------   457854        --------- 10001
    OUTPUT
    Three Idoc's to be created -- am able to create it basing upon delivery_date.
    But for 19/02/2006 this Idoc number there are different qty and different slnumber. So, I want to be created multiple segments in the same IDoc.
    Thanks.
    S.
    Edited by: Swarna on Sep 21, 2011 1:29 PM

    Hi Swarna,
           Please try with the below logic.
    DeliveryDate-->removecontext->sort->splitbyvaluechange->collapsecontext---IDOC
    concatsortUDFSegment
    coacat:
    Input1-OutputofFormatByExample1sort
    Input2-OutputofFormatByExample2sort
    FormatByExample1:
    input1:outputofsortbykey2
    input2:DeliverNo-removecontext-sort--splitbyvaluechange
    FormatByExample2:
    input1:outputofsortbykey1
    input2:DeliverNo-removecontext-sort--splitbyvaluechange
    sortbykey1:
    input1:DeliveryNo--removeContext
    input2:SlNumber--removecontext
    sortbykey2:
    input1:DeliveryNo--removeContext
    input2:qty--removecontext
    *ExecutionType of UDF is all values of context*
    public void UDF(String[] var1, ResultList result, Container container) throws StreamTransformationException{
              ArrayList aList = new ArrayList();
         for(int i=0;i<var1.length;i++){
              if(aList.contains(var1<i>))
                   continue;
              else{
                   aList.add(var1<i>);
                   result.addValue(var1<i>);
    Thanks
    Priyanka

  • Unable to install AcrobatProDC to convert pdf to power point can it be done with Pro?

    I'm unable to install AcrobateProDC to convert pdfs to powerpoint, can it be done with AcrobatPro?

    Hi markn117,
    Could you please let me know what version of OS are you using.
    Please ensure that you are signed in as administrator and anti-virus software is disabled temporarily as that might interrupt the installation process.
    What exactly happens when you try to install Acrobat DC? Does the installation stuck in between?
    Is there any message dialog box that prompts on your screen?
    Using Acrobat Pro DC, you can definitely export any PDF to PowerPoint with ease.
    Let me know more so that I can help you out with the same.
    Regards,
    Anubha

  • Attempting to add aditional functionality to my program. Can it be done?

    I play online poker. I've written a program that keeps track of poker hands I've played, as well as the players I've played against. After every hand, the poker client writes the hand to a text file. My program reads these text files, extracts certain information regarding the hands and stores it in a database.
    I want to add the functionality to the program that would enable it to be aware of things that are happening during the course of a hand; i.e, what cards are displayed on the board, what action each player has taken (raise, bet, check, etc.), how much each player bets, etc. These things can easily be attained AFTER the hand is over by reading through the text file that is saved, but I want the program to have access to this information DURING the hand, so I can have it preform various calculations and various other tasks.
    Now, I'm not sure how to go about doing this, nor am I sure if this can even be done in java. I expect what I would need to do is have the program intercept the data which represents various things - actions taken by players, bet sizes, displayed cards, etc - that is transfered between the poker client and server . Or, perhaps, there is a simpler, more obvious solution to this.
    So, is there any way to do the above with the proposed solution? If not, is there any other way that my program can work with the poker client itself in order to obtain the desired information without dealing with the interaction between the poker client and server?

    Who does this and how? Is the progam dumping this information? Are you manually entering it? Or did you actually write a program that is doing this? And how does it work?What happens is after a hand is completed, the poker client writes the hand to a text file. My program reads through this text file and extracts certain information. So, the text file looks something like this:
    Seat 4: player 1 ($156.50 in chips)
    Seat 6: player 2 ($17.50 in chips)
    player 1: posts small blind $1
    player 2: posts big blind $2
    *** HOLE CARDS ***
    Dealt to player 1 [9s Js]
    player 1: raises $2 to $4
    player 2: raises $2 to $6
    player 1: calls $2
    *** FLOP *** [3d As Jh]
    player 2: bets $2
    player 1: calls $2
    *** TURN *** [3d As Jh] [3h]
    player 2: bets $4
    player 1: raises $4 to $8
    player 2: calls $4
    *** RIVER *** [3d As Jh 3h] [6s]
    player 2: bets $4
    player 1: calls $4
    *** SHOW DOWN ***
    player 2: shows [Ah Kd] (two pair, Aces and Threes)
    player 1: mucks hand
    player 2 collected $39 from pot
    *** SUMMARY ***
    Total pot $41 | Rake $2
    Board [3d As Jh 3h 6s]
    Seat 3: player 2(big blind) showed [Ah Kd] and won ($39) with two pair, Aces and Threes
    Seat 4: player 1 mucked [9s Js]
    So my program just parses this text and extracts certain information, then saves it to a database I created using JDBC. I can then access this info through the GUI I created.
    This question is problematic because I don't see how if you actually wrote a program that actually does something that you couldn't make it working during the game and not just after. What I suspect is happening is that either the client is dumping this information for you or that you are manually capturing it.
    So can you describe how you are getting the information now exactly?The problem is that the text file is written to AFTER the hand takes place, not during. I'm looking for a way to access what is taking place in the hand, during the hand and not after.
    Is that helfpul at all?

  • Trying to convert NEF photos to JPEG photos can it be done in pse12 and if so how?

    trying to convert NEF files to JPEG files in pse12 can it be done and if so how?

    Hi,
    Both of those cameras should be supported by PSE 12.
    Just open the NEF file in the editor. It will first load the camera raw where you can do some adjustment.
    When satisfied, make sure that the bit depth option is set to 8 bits/channel (bottom middle of camera raw window).
    Click on Open Image to open the image in the main editor window.
    Make any further adjustments you want to and then go to the File menu and select Save As
    Change the format to JPEG, change the name if you want to and then click on Save.
    You can adjust the quality on the next box (higher quality = larger file)
    If you get a message about unsupported file format, it could be that you have use the old Nikon transfer program to copy the images from the card to your hard drive. This is knoow to cause corruption. See the following for a tool to correct the files.
    http://owl.phy.queensu.ca/~phil/exiftool/fix_corrupted_nef.html
    Good luck
    Brian

  • Can PSE8 for mac convert an 8 bit image to 16 bit?

    can Photoshop Elements 8 for mac convert an 8 bit image to 16 bit?
    I use Photomatix Pro and when I am working with a single image in Photomatix Pro, it has to be 16 bit.

    Yes, you can. These are the steps when using the elements editor.
    Depending on the file format:
    1. If this file is from a camera raw file, simply open the original
        raw file and at the bottom of the camera raw dialog choose 16 bits.
        This would open the file in pse editor as a 16 bit file.
        Then save as a tif file with no compression.
    2. If the file is a jpg or tif file, in the pse editor select: File>Open As>Camera Raw.
        This will open the file in the camera raw dialog. Then select 16 bit from the menu
        at the bottom of the camera raw dialog. After the file opens in pse editor, in 16 bits,
        save as a tif with no compression.
    3. If the file is a psd file with no layers, then step 2 will work. If the psd file has layers,
        open the the file in pse editor and resave the file using maximize compatibilty.
        This will allow the psd file to have both layers and open in the camera raw dialog as
        in step 2. When you open the file in the pse editor, it will just be a single layer and then
        just save as a tif file with no compression.
    Hope this helps.
    MTSTUNER

  • Converting byte[] to Class without using defineClass() in ClassLoader

    so as to de-serialize objects that do not have their class definitions loaded yet, i am over-riding resolveClass() in ObjectInputStream .
    within resolveClass() i invoke findClass() on a network-based ClassLoader i created .
    within findClass() , i invoke
    Class remoteClass = defineClass(className, classImage, 0, classImage.length);
    and that is where i transform a byte[] into a Class , and then finally return a value for the resolveClass() method.
    this seems like a lengthy process. i mean, within resolveClass() i can grab the correct byte[] over the network.
    then, if i could only convert this byte[] to a Class within resolveClass() , i would never need to extended ClassLoader and over-ride findClass() .
    i assume that the only way to convert a byte[] to a Class is using defineClass() which is hidden deep within ClassLoader ? there is something going on under the hood i am sure. otherwise, why not a method to directly convert byte[] to a Class ? the byte[] representation of a Class always starts with hex CAFEBABE, and then i'm sure there is a standard way to structure the byte[] .
    my core issue is:
    i am sending objects over an ObjectInputStream created from a Socket .
    at the minimum, i can see that resolveClass() within ObjectInputStream must be invoked at least once .
    but then after that, since the relevant classes for de-serialization have been gotten over the network, i don't want to cascade all the way down to where i must invoke:
    Class remoteClass = defineClass(className, classImage, 0, classImage.length);
    again. so, right now, within resolveClass() i am using a Map<String, Class> to create the following class cache:
    cache.put(objectStreamClass.getName(), Class);
    once loaded, a class should stay loaded (even if its loaded in the run-time), i think? but this is not working. each de-serialization cascades down to defineClass() .
    so, i want to short-circuit the need to get the class within the resolveClass() method (ie. invoke defineClass() only once),
    but using a Map<String, Class> cache looks really stupid and certainly a hack.
    that is the best i can do to explain my issue. if you read this far, thanks.

    ok. stupid question:
    for me to use URLClassLoader , i am going to need to write a bare-bones HTTP server to handle the class requests, right?Wrong. You have to deploy one, but what's wrong with Apache for example? It's free, for a start.
    and, i should easily be able to do this using the com.sun.net.httpserver library, right?Why would you bother when free working HTTP servers are already available?

  • Is possible to Convert a 1 bit B&W Tiff image to a 16 Bit Greyscale Tiff image?

    Hi there,
    I am trying to convert a 1 bit Black & White Tiff image to a 16 Bit Greyscale Tiff image, Anyone out there know if it is possible and how it may be done? We are using Adobe Acrobat 9 Pro Extended.
    Any help would be appreciated.
    Cheers, Chris

    Almost any graphic editor can do it, but it doesn't make a sense. The picture information remain the same - 1 bit. It has nothing to do with Acrobat.

  • Speech recognition with Flash- Can it be done?

    is there any way in flash to detect the voice and detect what
    user is saying.
    eg if user is saying "yes" then run some command and if "no"
    then other.

    David,
    > Flash project can have an interface where
    Illustrator/PDF files
    > could be opened from within a Flash Projector file
    allowing
    > users to turn on/off layers of graphics per their needs
    and then
    > print out the results
    Photoshop and Illustrator files are supported for input in
    the Flash
    authoring tool -- even to the point of turning on/off layers
    -- but for
    better or worse, Flash Player doesn't support either format
    at runtime.
    (They're converted to Flash Player-compatible files by the
    authoring tool.)
    I won't go so far as to say this definitively can't be done
    a.viary.com does some amazing Photoshop-like things using
    Flash, and recent
    ActionScript does allow for manipulation of byte arrays -- so
    desktop
    control over PSDs and AIs *might* be possible in theory, but
    it would be the
    sort of custom programming that a only handful of the top
    Flash developers
    in the world would know how to do.
    David Stiller
    Adobe Community Expert
    Dev blog,
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • 24-bit audio files converted to 16-bit in Logic Pro 7

    Hello,
    I'm working on producing my band's demo and this is my first project in Logic Pro 7. The tracks were originally recorded into a Fostex D2424LV hard disc recorder as 24-bit wave files, then imported into Logic. At this point, I've done the editing and effects processing in Logic and exported the tracks as individual wave files, with the intent to put the tracks back on the Fostex and run them through a Yamaha 24-channel analog board for the final mixdown.
    Everything has gone smooth until now. When I play the exported tracks back on the Fostex, most of them are peaking on the meters, while the same tracks played back in Logic don't even come close to peaking. I've tried re-exporting the tracks with reduced fader levels and still get peaks on the Fostex.
    Given that the reduced levels still cause tracks to peak on the Fostex, I'm suspecting a bit-depth issue. I didn't realize at the time that the files were converted to 16-bit when they were imported into Logic. The Fostex only works with 24-bit files and I'm wondering if exporting the 16-bit tracks in Logic as 24-bit wave files might be causing the problem.
    If this turns out to be the cause of the peaking tracks, is it possible to re-import or replace the converted 16-bit files with the original 24-bit files and apply the editing and efx processing that I've done to the 24-bit files?
    I'll greatly appreciate any help you folks can give me on this one.
    Kevin
    Dual 2.0 Ghz G5 Powermac   Mac OS X (10.4.1)   RME Multiface
    Dual 2.0 Ghz G5 Powermac   Mac OS X (10.4.1)   RME Multiface

    i am very surprised that the fostex doesn't work with 24-bit files.
    your peaking is not likely to be due to bit depth, although i can see why you might think so. maybe you're right.
    logic has inbuilt -6db of head room you should know.
    your suggestion of reimporting the original tracks from the fostex is exactly the thing you should do. remove the 16-bit files from the system and re-import the fostex files. open the logic project and it will look for the old files. for greatest ease make sure your fostex imported files have the same names as the ones you are removing. when it finds the files with the same name it should come up with an error message. select use anyway.
    what's happening is logic stores information about the file, its length, bit-depth and so forth. so just get logic to use anyway and the files "should" playback alright.

Maybe you are looking for

  • Can't upload photos from ipod touch to computer

    How do you take photos from the ipod touch to the computer??? I need to be able to transfer my photos soon!!!

  • When to use unattend.xml in task sequence - best practice?

    Hi, I've tried researching this but not found an answer to my specific query. We have ConfigMgr 2012 R2 with MDT 2013 although I don't think this is an MDT specific question. I'm trying to create a Build and Capture task sequence for our Windows Serv

  • Changing the table-color

    I built a Master/Detail application using Dreamweaver Developer Toolbox. I would like to change the gray color of the tables to other colors that are more suitable to my site. Is there anybody that can help me accomplish that ? Amanda Nguyen

  • No Computer Name for Mountain Lion clients

    Hi guys, Have anyone else seen or have a fix for Mountain Lion clients Computer names being displayed as "-" in Apple Remote Desktop Admin 3.6.1 and client? I've deleted preferences and re-scanned with the same results

  • Button if not clicked within stipulated time jump to assigned slide

    The background image is actually a video that's being played and as the switch is approaching the user has to either proceed or stop...Since this switch is aligned the right way the user is supposed to hit proceed button. In this switch stop button w