Please help me to get a clue from this program

I'm sorry to bother you with such stupid questions. I have to admit I'm just making my first steps in programming.
So I have a program like this and don't understand how it works:
// Masking sign extension.
class HexByte {
static public void main(String args[]) {
char hex[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
byte b = (byte) 0xf1;
System.out.println("b = 0x" + hex[(b >> 4) & 0x0f] + hex[b & 0x0f]);
Specifically, how could 0xf1 be represented in binary? As far as I know 11110001 contains negative value. Moreover 0xf1 in 10's base is 241, so how can I convert it to byte? Doin so, I'm gonna lose its value (since the byte range is from -128 to 127). And why do I need it? I even have no idea how the variable would look like in binary after converting to byte, not mentioning last part of this program.
I would really appreaciate your help.
Thank you for your time.

AntShay wrote:
Thank you so much for your help guys. Now I got just 2 more questions. First of all. I guess sign-extension works only with negative values. Is that correct? When sign-extension takes place and I shift any value to the right by any number of positions, does it fill in all the previous bits with *1s*? If you can, please, tell me how exactly this works.Java primitives are all signed, so sign extension is always at work for right bit shifts. However, if you were to look into the code, it has masked away the 4 most significant bits using bit-wise and operation. Alternatively, you may use the unsigned shift (+>>>+) operator.
And by the way, is there any method to convert the value of byte to a binary string? I only figured that it might work this way: Integer.toBinaryString(b&0xff), but is there Byte.toBinaryString method or something?It is always okay to up cast, as sign extension will convert correctly. If you don't like the long integer output, you may do a substring() on the output. It is also not hard to roll your own.

Similar Messages

  • Please help how to get return array from rpg program on java code?

    Hi
    I have created a rpg program that returns 2 parameter 1 is the id and another one is list of array, when I called this program I passed two programparameter from my java code (see the code below) but when i checked what value would be return it is returned only first value of array. how will i get all array values ?
    please suggest me regarding this issues I amn't so much aware on java & AS400.
    try
    ProgramParameter[] parmList = new ProgramParameter[2];
    AS400Text p1 = new AS400Text(10);
    AS400Text p2 = new AS400Text(30);
    try
    parmList[0] = new ProgramParameter(10);
    parmList[1] = new ProgramParameter(30);
    parmList[0].setParameterType(ProgramParameter.PASS_BY_REFEREN CE);
    parmList[1].setParameterType(ProgramParameter.PASS_BY_REFEREN CE);
    parmList[0].setInputData(p1.toBytes("Pune"));
    parmList[1].setInputData(p2.toBytes(" "));
    catch(Exception ex)
    ProgramCall pgm = new ProgramCall(o);
    pgm.setProgram("/QSYS.LIB/XXX/XXX.PGM",parmList);
    if (pgm.run())
    byte s[] = parmList[1].getOutputData(); // HERE I got only first value of returning array.
    parmList[1].getOutputDataLength();
    //String sts = ((String) (new AS400Text(10,o).toBytes(s[0])));
    else
    AS400Message[] messageList = pgm.getMessageList();
    for (int msg = 0; msg < messageList.length; msg++) {
    catch(Exception ex)
    AS400Message[] messageList = null;
    finally
    o.disconnectAllServices();
    Reply With Quote

    Try this :
    try
    ProgramParameter[] parmList = new ProgramParameter[2];
    AS400Text p1 = new AS400Text(10);
    AS400Text p2 = new AS400Text(30);
    AS400Array arrP2 = new AS400Array(p2, 4);
    try
    parmList[0] = new ProgramParameter(10);
    parmList[1] = new ProgramParameter(30);
    parmList[0].setParameterType(ProgramParameter.PASS_BY_REFEREN CE);
    parmList[1].setParameterType(ProgramParameter.PASS_BY_REFEREN CE);
    parmList[0].setInputData(p1.toBytes("Pune"));
    parmList[1].setInputData(arrP2.toBytes({"","","",""}));
    catch(Exception ex)
    ProgramCall pgm = new ProgramCall(o);
    pgm.setProgram("/QSYS.LIB/XXX/XXX.PGM",parmList);
    if (pgm.run())
         Object[] objArr =  (Object [])arrP2.toObject( parmList[1].getOutputData() );
         for(int i =0; i<objArr.length;i++){
                System.out.println( " SKU " + i +" : " + objArr.toString());
    else
    AS400Message[] messageList = pgm.getMessageList();
    for (int msg = 0; msg < messageList.length; msg++) {
    catch(Exception ex)
    AS400Message[] messageList = null;
    finally
    o.disconnectAllServices();

  • Hi, would you please help me to get red of hips of emails that I am receiving from this site? I want to delete my profile. How can I do it?

    Hi, would you please help me to get red of hips of emails that I am receiving from this site? I want to delete my profile. How can I do it?

    Read Frank Caggiano's User Tip here: Stopping emails from ASC

  • Hi, please help me , i get notification about a new update for my iPad when I do the instal for the new version it is asking me for a passcode but which passcode may I have to enter? Because when I enter my gmail passcode it is call me that my pass fail

    Hi, please help me , i get notification about a new update for my iPad when I do the instal for the new version it is asking me for a passcode but which passcode may I have to enter? Because when I enter my gmail passcode it is call me that my passcode is failed

    The passcode you need to enter is the passcode you set on your device. It is the passcode that you enter when you turn on your iPad or awaken it from sleep after and Auto lock.
    If you do not know or remember your password and did not store it somewhere then you will have to restore your device.
    http://support.apple.com/kb/HT1212

  • I upgraded to 20gb iCloud but it isn't enough to back up. I get constant error messages saying there is no backup space and I've not been able to use the upgrade. Apple promised to refund then didn't. Please help is there anyway I can use this space?

    Please see the subject line thanks
    I upgraded to 20gb iCloud but it isn't enough to back up. I get constant error messages saying there is no backup space and I've not been able to use the upgrade. Apple promised to refund then didn't. Please help is there anyway I can use this space?

    If you were told they would refund the price for the iCloud storage - Contact AppleCare and ask to speak with a senior advisor.  Have the case number for the promised refund available.
    If you are trying to update your device, but you don't have sufficient space to download and install the update, you need to delete content from your device.  Buying storage in iCloud does not add space to the device which is what you need.
    You can always update using a computer with iTunes installed - this method is faster, and will allow you to make a backup on the local computer (Local backups restore faster than iCloud backups).
    HTH

  • Please help me to get Oracle 10.2.0.5 software for 64 bit Windows 2008 R2

    Hi All,
    Subject: Please help me to get Oracle 10.2.0.5 software for 64 bit Windows 2008 R2 operating system.
    I am looking for Oracle 10.2.0.5 software to install in windows 2008 server (64 bit) R2. I tried with oracle download repository but unfortunately I couldnt find this software. In the below link I can see the product Oracle 10.2.0.5 - 64 bit (Itanium). I have tried to download and install in the server but I received in-compatible error message.
    http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html
    From the oracle support certification site I have found that the Oracle 10.2.0.5 is the compatible version to installed in windows 2008 server(64) R2.
    I am trying very hard to find Oracle 10.2.0.5 - 64 bit. Can you please suggest me where I can download this software.
    Please do the needful.
    Regards,
    Jame

    Hi;
    Which means, do i need to install 10.2.0.4 and then to upgrade 10.2.0.5 using patchset?10.2.0.1 is base relase 10.2.0.x is patchest. 10.2.0.5 cover previous patchest errors which mean you do not need install 10.2.0.4 than upgrade it 10.2.0.5
    Regard
    Helios

  • Please help.  Keep getting a conversion error when trying to convert a PDF to a .docx. Advice?

    Please help.  Keep getting a conversion error when trying to convert a PDF to a .docx. Advice?

    Sara,
    Please see my answers in bold below.
    What browser are you using? Try clearing the cache, or using a different browser. N/A
    Are you converting from within Reader, or directly via the ExportPDF website. Within Reader.I disabled the OCR and this did not work either. Try converting from within Reader, and disable OCR as detailed in this document: How to disable Optical Character Recognition (OCR) when converting PDF to Word or Excel.
    Are you on a networked computer? Make sure that there aren't any firewall/proxy settings that are preventing you from uploading files to the Internet. Not having problems uploading the file--that works fine.
    Make sure the file is within the file-size limit of 100 MB. It is <40.
    I get the error message, "File failed to be converted using Adobe ExportPDF online."
    Thanks for your help in advance.

  • Hi, I recently updated my IOS to 7.1.1. After few days the camera apps is missing. I'm not able to find camera anywhere in my mobile. Please help me to get it back. thanks

    Hi, I recently updated my IOS to 7.1.1. After few days the camera apps is missing. I'm not able to find camera anywhere in my mobile. Please help me to get it back. thanks

    Hello there, Kumarlmk.
    The following Featured Discussion deals with the issue you seem to be describing and provides some workable solutions:
    The Camera app is suddenly missing from...: Apple Support Communities
    https://discussions.apple.com/thread/5284736
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • TS2446 Please help me,I can not purchase from apple store becuse it is ask me the secirty question in my apple ID but I forget my secrity question

    Hello,
    Please help me,I can not purchase from apple store becuse it is ask me about the secirty question in my apple ID but I forget my secrity question.
    Thanks,

    If you can't remember them then go to Express Lane  and select 'iTunes' from the list of 'products' in the middle of the screen.
    Then select 'iTunes Store', and on the next screen select 'Account Management'
    Next choose 'iTunes Store Account Security' and fill in that you'd like your security questions/answers reset.
    You should get an email reply within about 24 to 48 hours (and check your Spam folder as well as your Inbox). A month or two ago Apple had temporarily suspended the reseting of security question/answers whilst account security processes were improved, but that may now have finished.

  • I accidently deleted my icloud a/c and lost some of my important contacts , please help me in getting them back.

    I accidently deleted my icloud a/c and lost some of my important contacts , please help me in getting them back.

    Hey ashvinee,
    Sorry to hear you're having difficulty with your contacts. We have a few articles that could resolve your issue.
    I would start here:
    iCloud: Troubleshooting iCloud Contacts
    http://support.apple.com/kb/ts3998
    Recovering iCloud or MobileMe data from iTunes backups for an iOS device
    http://support.apple.com/kb/TS4108
    This second article applies to you if:
    You want to recover your Contacts, Calendars, and Bookmarks from an iTunes iOS device backup made while using iCloud or MobileMe to update your Contacts, Calendars, and Bookmarks on your iOS device.
    You have created backups in iTunes, and you do not have or are unable to restore from an iCloud Backup. Learn more about how to restore from an iCloud Backup.
    You have lost data from the web, your iOS device, and all other synchronized clients, and you have no other usable backups to recover from.
    Cheers,
    David

  • My phone wont let me download anything even free stuff or update.it keep saying something wrong with my billing info so i fix it but still cant download.I signed out sign back in still nothing please help i'm getting angry

    My phone wont let me download anything even free stuff or update.it keep saying something wrong with my billing info so i fix it but still cant download.I signed out sign back in still nothing please help i'm getting angry

    If it says your billing info is wrong that means that your credit card issuer is refusing to approve your account. You will have to solve the problem with your bank or credit card company.

  • In my mac i dont create icloud keychain but it is asking password please help me to get out of this problem

    In my mac book pro i don't create icloud keychain. But it is asking password.Please help me to get out of this problem.In OS X Mavericks

    Hi, nportillo,
    The next time you attempt to reach Skype Customer Service, try again using a different web browser and choosing a different path through the various drop-down menu options presented.  Do not choose the obvious - you have already established that path is not working.  Also, look to approve a pop-up dialogue box which would connect you to start an instant message chat with a customer service agent. If you have pop-ups blocked in your browser settings, this will also impede reaching an agent.
    Skype is aware of problems reaching their customer service unit via the website, however people are getting through.  I have flagged your report for follow-up by those to whom I report.
    Regards,
    Elaine
    Was your question answered? Please click on the Accept as a Solution link so everyone can quickly find what works! Like a post or want to say, "Thank You" - ?? Click on the Kudos button!
    Trustworthy information: Brian Krebs: 3 Basic Rules for Online Safety and Consumer Reports: Guide to Internet Security Online Safety Tip: Change your passwords often!

  • My 4th generation ipod touch is not turning off when i hold the wake button for few seconds the Voice Control Function Starts Automatically.Please help me to get out of this problem.

    My 4th generation ipod touch is not turning off when i hold the wake button for few seconds the Voice Control Function Starts Automatically.Please help me to get out of this problem.

    Sorry i mistakenly made this question. It was alright. No Problem At ALL

  • Please help: Example how to peploy application from jar file step by step

    Please help: Example how to peploy application from jar file step by step.
    All help appreciated
    Mike

    Thanks I will try these links
    Mike
    "Slava Imeshev" <[email protected]> wrote:
    Hi Mike,
    These links could be useful:
    http://e-docs.bea.com/wls/docs61////adminguide/appman.html
    http://e-docs.bea.com/wls/docs61////quickstart/quick_start.html
    http://e-docs.bea.com/wls/docs61//////ConsoleHelp/application.html
    http://e-docs.bea.com/wls/docs61///programming/environment.html
    Regards,
    Slava Imeshev
    "Mike" <[email protected]> wrote in message
    news:3ca0e94c$[email protected]..
    Please help: Example how to peploy application from jar file step bystep.
    All help appreciated
    Mike

  • I have updated my ipad4 to ios7 and then I couldn't find my personal hotspot option.... Please please please help me to get back .... I really need help

    I have updated my ipad4 to ios7 and then I couldn't find my personal hotspot option.... Please please please help me to get back .... I really need help

    First thing to try is to reset your device. Press and hold the Home and Sleep buttons simultaneously until the Apple logo appears. Let go of the buttons and let the device restart. See if that fixes your problem.
    Personal Hotspot should be at Settings > Cellular Data > Personal Hotspot

Maybe you are looking for

  • Macbook pro freezes with purple pixels

    My macbook doesn't want to boot up. I just get the apple with the rotating wheel that goes on for about 60 seconds. Then it either freezes or magically goes to the desktop. If it does get past the freezing spin wheel to the desktop, I have only a mat

  • Insert 'illegal' characters into file name for print label?

    Hey all (Happy New Year) I actually see some people here who helped me with this originally so many years ago (hi 'x'). Any way, I'm using this .js file to annotate aerial imagery prior to printing, and I know just enough about scripting to make chan

  • HT3939 is there an update for iPhone 4 A1332?

    is there an update for iPhone 4 A1332? It seems lately every ap I try to load requires a different system.

  • Filters in CC

    Having just rented CCand Lightroom and found that some filters available on CS5 are not on CC, Artistic and Sketch for example. Is this correct

  • WLC 2504 Guest Wifi login Page

    Hi Need some help. I have setup guest access on the controller and this is not working at the moment. DHCP server setup on the controller for the Guest users. You are able to connect (get ip address from controller) and the browser gets redirected to