From byte to long

Hi
A very easy question. Imagine the byte 0xFF (Or 11111111). I want to build a long (64 bits length) having this byte on the last 8 bits starting from the right. That is:
0000000....0000011111111
If a write long l = (long) b, then l is -1 (Or 111111...11111). Is there any way to do this? Thanks in advance.

byte b = (byte)0xff;
long l = b;
l &= 0xff;This solution works but this is not what I am looking
for. Imagine that you do not know the value of the
byte. This byte is only a variable. And the purpose
is to set this byte at the end of the long bit
String, that is, the first 8 bits starting from the
right. Any ideas?That's exactly what the code does. You should only change the value of b.
Kaj

Similar Messages

  • How do I add multiple songs to an existing playlist from the (no longer called) Library? Highlighting multiple songs and clicking the "Add to" button will only add the with the little arrow, not all the highlighted ones!

    How do I add multiple songs to an existing playlist from the (no longer called) Library? Highlighting multiple songs and clicking the "Add to" button will only add the one with the little arrow, not all the highlighted ones! I am using the "new" iTunes.

    For the moment there isn't a way for us end-users to control what is "matched" or "uploaded." That is purely a result of Apple's server-side algorithms.
    To re-add multiple songs at once simply highlight all the songs you want to re-add, then right-click (or Control+click) the list and choose "add to iCloud."

  • Some older addresses that sync from Outlook no longer showup on my ipad and iphone.  Data is in Outlook and in Icloud contacts.  Any suggestions?

    Some older addresses that sync from Outlook no longer showup on my ipad and iphone.  Data is in Outlook and in Icloud contacts.  Any suggestions?  Some of the newer addresses seem to sync but the older ones (family) addresses are not.  The data is showing up in Outlook and in icloud but doesn't show up in my contacts after a sync.

    Hi dlzimmie,
    Thanks for using Apple Support Communities.  This article has some troubleshooting for contacts syncing issues that may help:
    iCloud: Troubleshooting iCloud Contacts
    http://support.apple.com/kb/TS3998
    Cheers,
    - Ari

  • DVD's from IDVD no longer work in a Blue-Ray DVR for television.  Who changed what and why?

    DVD's from IDVD no longer work in a Blue-Ray DVR for television.  Who changed what and why?

    Hi
    What BRAND of the DVD used ?
    What type of DVD ? SL-DVD-R or DL-DVD-+RW or ?
    Burn Speed ? Did Yo set it down ? I do to x2
    Cleaning DVD disk (not with liquid but the ones with brushes) - I use from time to time ?
    Free Space on Start-Up (Maintosh HD) - How much ?
    Yours Bengt W

  • Embedding html from youtube no longer works

    embedding html from youtube no longer works??

    You need to select the 'Enhanced Privacy' check box in YouTube before getting your embed code.

  • Convert from String to Long

    Hello Frineds I want to convert from String to Long.
    My String is like str="600 700 250 300" and I want to convert it to long and
    get the total value in to the long variable.like the total of str in long varible should be 1850.
    Thank You
    Nilesh Vasani

    Maybe this would work?
    StringTokenizer st = new StringTokenizer(yourString, " ");
    long l = 0;
    while(st.hasMoreTokens()) {
        l += Long.parseLong(st.nextToken()).longValue();
    }

  • Byte[] to long

    I'm writing an app that needs to deliver data to different places based on source and destination IP addresses. I was thinking that I could do this by stuffing the bits of both addresses into a long (source followed by destination) and then making a binary tree out of them.
    Assuming I can get the addresses as byte arrays, would doing this:
    long getAddresses(){
    byte[] source=getSource();
    byte[] dest=getDest();
    long addresses= source[0]|source[1]|......source[7]|dest[0]|dest[1]|.....dest[7]; //pardon the paraphrasing
    return addresses;
    be the best way to go about things? I don't really care about the value of the longs, I only need to be able to compare them against each other and be sure that all pairs of addresses will produce a unique value, and as quickly as possible, since I need to handle lots of them.
    Thanks for any advice.
    Ewan

    Well, if you don't really care obout the actual long values, a little byte-collecting
    helper function will do:private long collect(byte[] b, long l) {
       for (int i= 0; i < b.length; i++) {
          l<<= 8;
          l|= b&0xffL;
    return l;
    Your getAddresses() might look like this then:long getAddresses(); {
       long l= collect(getSource(), 0);
       return collect(getDest(), l);
    }kind regards,
    Jos

  • Why do embeded presentations from Prezi no longer work?

    Embeded interactive presentations from Prezi no longer work, when viewed on Firefox. They still work fine, when viewed on Google. This is a problem whether I am signed on or not.

    You can try basic steps like these in case of issues with web pages:
    Reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
    *Hold down the Shift key and left-click the Reload button
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Command + Shift + R" (Mac)
    Clear the cache and the cookies from websites that cause problems.
    "Clear the Cache":
    *Firefox/Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Firefox/Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    Note that your System Details List shows that you have a user.js file in the profile folder to initialize some prefs on each start of Firefox.
    The user.js file is only present if you or other software has created it, so normally it wouldn't be there.
    You should check its content with a plain text editor if you didn't create this file yourself.
    The user.js file is read each time you start Firefox and initializes preferences to the value specified in this file, so preferences set via user.js can only be changed temporarily for the current session.
    *http://kb.mozillazine.org/Preferences_not_saved

  • NLS_LENGTH_SEMENTICS from BYTE TO CHAR

    Hi,
    For supporting multibyte character, we need to change NLS_LENGTH_SEMENTICS parameter from BYTE to CHAR. But this parameter setting will effect for new database tables created thereafter. To change the storage characteristics for existing database tables we explicitly executed Alter statements for database tables for columns having datatype as “Varchar2” and “Char”.
    Problem:
    ======
    Since the number of database tables in PRODUCTION are very high and contains approx. 600 million of records spread over 400 database tables, we are not in a position to afford the time which will be spent in altering these database tables in PRODUCTION.
    We ran the test by alter script in System Test environment and alteration of database tables covering 150 tables and 200 million of records was carried out in almost 16-20 hrs.
    APPROACHES WE HAVE IN MIND
    ==========================
    1. Alter all the table columns (We tried the same and taking too much time)
    2. Export /Import with NLS_LENGTH_SEMENTICS set as CHAR(We discuss with our DBA about this approach and found that it will also take too much time and there is RISK of data inconsistency)
    3. Drop the index of the table, run alter script for changing storage type BYTE to CHAR , and rebuild the index (this is also taking too much time).
    All above approaches are very costly in terms of time, that we cannot afford.
    If any one having better solution then please suggest.
    thanks in advance
    Syed

    Hi
    We are also facing a similar problem
    We ran alter table scripts and now compiling the objects
    and that is taking lot of time.
    we have around 4000 invalids that by parallel recomp came down to 2000 but still these 2000 which are mostly packages .. are giving a hard time.
    if anyone has faced/found a similar issue/solution pls post. or maildirectly to me.
    Sunil Choudhary

  • Lync BToE - USB HeartBeat is not passed from Lync for long duration (more than 20 seconds)

    Lync BToE - USB HeartBeat is not passed from Lync for long duration (more than 20 seconds)

    Hi,
    Did the issue happen only for you or for multiple users?
    Make sure phone update to the latest firmware.
    Best Regards,
    Eason Huang
    Eason Huang
    TechNet Community Support

  • Coversion from byte stream to character & character to byte stream.

    This is a test program.
    import java.io.*;
    class Test
         public static void main(String[] args)
              System.out.println("Hello World!");
              try
                   BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("C:/javafiles/testing/Picture.jpg"))));
                   PrintWriter bw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File("C:/javafiles/testing/Copy.jpg"))));
                   String in = br.readLine();
                   while (in != null)
                        bw.println(in);
                        in = br.readLine();
                   br.close();
                   bw.close();
              catch (Exception e)
                   System.out.println("\n\n**********Exception Occured**************\n" + e);
    **First of all I read jpg file convert it into character stream from byte stream.
    **and copy it back and convert it back into byte steam from character stream.
    **The file copied back is corrupted.(getting open but display has fully scattered.)
    **That means data has been lost in conversion.
    **is it due to the encoding, I havn't specified while writing, or it always happens when we convert from byte stream to character and vice versa.
    **What encoding should I use while writing jpg files.
    please comment.

    **First of all I read jpg file convert it into
    character stream from byte stream.
    **and copy it back and convert it back into byte
    steam from character stream.First of all this operation is meaningless. A JPEG file doesn't contain anything that can be converted to characters. Delete the 'conversions' and all will be well.
    **What encoding should I use while writing jpg files.None. Don't use an encoding. Don't use Readers and Writers. Use InputStreams and OutputStreams only.

  • How Do I Keep My MBP From Working As Long As Possible

    Hi,
    I had a PowerBook G3 from Apple a long time ago. And the battary went out of work after I had the laptop for 3 years. And other parts of the PowerBook G3 like the hard disk and power supplier also went bad.
    Now I'm purchasing a new MacBook Pro, how do I keep the parts of my laptop not from out working? (like for the battery, do I keep it connected while I'm using my MBP at home?)
    Thanks.

    how do I keep the parts of my laptop not from out working?
    Aside from the battery, there is nothing specific you can do. Technology is not perfect, and can fail at any time.

  • Intermittent error saving attachments from mail: "Names longer than 31 characters are not supported on the destination volume."

    I am reciving intermittent errors saving attachments from mail: "Names longer than 31 characters are not supported on the destination volume."

    I am seeing this too.
    I Posted in similar thread 6704033
    Error when saving calendar exports-names longer than 31 characters not supported on the destination volume.
    Very spooky. Not always reproducible, but it happened to me while using Office365-Outlook web-based email (saving a PDF).
    RE: the suggestion, checking security box "allow apps downloaded from all sites" I would really rather not do that.
    On my system it is set to allow "Mac App store and identified developers."
    Oh sorry, I'm on Yosemite, I see this is Mav forum...

  • My ipod has a short battery life from charging too long.

    My ipod has a short battery life from charging too long. What can i do about it?

    please help

  • How can I get String from Bytes

    I want to get String from array of bytes but i have some trouble from byte that it's lager more than 128. How can I do ???
    Please hepl me. Thanks very much.

    This program is only to show you what the relationships are between unsigned byte, signed byte, character, and binary values. Because of the constraints that Java has, the program code is not especially clean. Run the program and see if it helps. As has been said, the character output is dependent on the encoding in use.
    Here is a sample of some of its output:
    Unsigned byte= 189 Signed byte= -67 Character= � Binary= 10111101
    Unsigned byte= 190 Signed byte= -66 Character= � Binary= 10111110
    Unsigned byte= 191 Signed byte= -65 Character= � Binary= 10111111
    Unsigned byte= 192 Signed byte= -64 Character= � Binary= 11000000
    Unsigned byte= 244 Signed byte= -12 Character= � Binary= 11110100
    Unsigned byte= 245 Signed byte= -11 Character= � Binary= 11110101
    Unsigned byte= 246 Signed byte= -10 Character= � Binary= 11110110
    public class ATest {
        public static void main(String[] args) {
            int in;
            byte by;
            String bin;
            char chr;
            for(in=0; in<256; in++) {
                // create a byte whose binary value is equal to the;
                // integer loop counter;
                by = (byte)in;
                // mask off sign extension [that I don't agree with!] and;
                // cast the resultant 8 bits to a char;
                chr = (char)(by & 0x00ff);
                // since there's no Byte.toInteger, must cast to int to get;
                // binary string and then delete unwanted portion of string;
                if(in<128) {
                    bin = Integer.toBinaryString((int)by);
                } else {
                    bin = Integer.toBinaryString((int)by).substring(24);
                // print everything;
                System.out.println(
                    "Unsigned byte= "+in+
                    " Signed byte= "+by+
                    " Character= "+chr+
                    " Binary= "+bin);
    }

Maybe you are looking for

  • How can I calculate the number of members with data for a given Dimension

    HiI want to be able to calculate the exact size of the data given the number of blocks in existence.I am trying to work out a way of estimating the effect of changing Dimensions from Spare to Dense and to see which Dimensions would be worth it.Curren

  • Hiding users in SM04

    Hi all...can some1 tell me how to hide users in SM04 for a particular user alone? i.e... none should not find tat particular user has been logged in from tat particular IP through anyway... is there any possibilities 2 do this?

  • CIC0 Partner determination different between crmd_order and CIC0

    Hi experts, We have a problem with the partner determination. We have a partner who has relations with several other partners. In the partner determination procedure, we have indicatied that the partner needs at most one occurence and a selection lim

  • Trouble when install solaris 10x86 on dell dimension 9100

    I just got my new dell dimension 9100 and I tried to install Solaris 10 on it but it didn't work. I could not type at all when the OS asked me what option do I want to install. It seems like the Solaris could not recognized the motherboard or somethi

  • Sidebar amnesia

    Hi, I have a couple of files and folders i added to the sidebar for quick access. After a few restarts, all the files and folders i put in are gone. This has been happening since 10.6 was installed. A clean install doesn't help and deleting the home