Byte to long conversion.

Hello.
If you run this code, the result is "-13".
Why this if "ó" value is 243?
Thanks.
public class prueba3
public static void main(String args[])
byte[] b="óxxfd".getBytes();
long b64=0;
b64=(long)b[0];
System.out.println(b64);
}

Hi elchaschab.
Your method works, but needs a minimal of an Array of 8 bytes to work and consumes much processor in long process, like for example in array of 65555 bytes.
I have proven the following code, but she does not convince to me because Java must to be able of a simple form to turn a byte to long without problems, no?
public class prueba3
public static void main(String args[])
byte[] b="óxxfd".getBytes();
long b64=0;
for(int cont=0;cont<b.length;cont++) {
b64=(long)b[cont];
if(b64<0) b64=((b[cont]^254)*-1); // This line run ok, turns only the signed values to unsigned.
System.out.println("b64("+((char)b[cont])+")="+b64);

Similar Messages

  • I have the Iphone4 and have a few txt msgs that are long conversations that I would like to send to my email account to have a record of them.  Is there a way I can do that?  Thnx!

    I have the Iphone4 and have a few txt msgs that are long conversations that I would like to send to my email account to have a record of them.  Is there a way I can do that?  Thnx!

    Try the computer apps PhoneView (Mac) or TouchCopy (Mac & PC):
    http://www.ecamm.com/mac/phoneview/
    http://www.wideanglesoftware.com/touchcopy/index.php

  • 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

  • Does Spatial support "Earth Centered, Earth Fixed" to Lat/Long conversion?

    Does Spatial support "Earth Centered, Earth Fixed" to Lat/Long conversion? I've looked in coordinate list table but don't see "ECEF" (or anything that might by a synonym for ECEF) listed.
    Thanks,
    Julien

    Spatial does not support ECEF coordinates at this time, nor conversions to/from longitude, latitude, and height above the ellipsoid. It is possible that Spatial will support ECEF in a future release of the product.

  • 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

  • Newbie: Earth Centered Earth Fixed - Lat/Long Conversion, can it be done w/ Spatial?

    This is an information request from a complete coordinate systems newbie:
    1. Does Oracle Spatial in 9.0.1 have an entry in MDSYS.CS_SRS that
    corresponds to the coordinate system commonly known as "Earth Centered, Earth
    Fixed" - where would I look (besides the table itself - I already tried that
    with the 8.1.7 EE to no avail - it may be because I don't know enough about how
    coordinate systems are referenced (the common nomenclature used) and just
    didn't recognize it when I saw it.)
    2. Are there any existing pl/sql snippets of code that can handle coordinate
    conversions between ECEF-Lat/Long, geodetic degrees-decimal degrees? (If yes,
    where should I go to look for them? By the way, please, please say yes, there
    are many such packages just like there are for unit conversions (like binary to
    hex).)
    3. Where should I look to get information on a product called Map Viewer which
    was mentioned in the latest edition of Oracle Magazine (May/June 2002, p.25 -
    it was said to be a part of the 9iAS suite of products - I looked all over the
    documentation but didn't find any mention of it.)
    Thank you very much for your time and attention!
    Julien

    This is an information request from a complete coordinate systems newbie:
    1. Does Oracle Spatial in 9.0.1 have an entry in MDSYS.CS_SRS that
    corresponds to the coordinate system commonly known as "Earth Centered, Earth
    Fixed" - where would I look (besides the table itself - I already tried that
    with the 8.1.7 EE to no avail - it may be because I don't know enough about how
    coordinate systems are referenced (the common nomenclature used) and just
    didn't recognize it when I saw it.)
    2. Are there any existing pl/sql snippets of code that can handle coordinate
    conversions between ECEF-Lat/Long, geodetic degrees-decimal degrees? (If yes,
    where should I go to look for them? By the way, please, please say yes, there
    are many such packages just like there are for unit conversions (like binary to
    hex).)You can get the proper params from the EPSG <http://www.epsg.org>,
    I recall seeing some coord conversion samples in the tutorials/sample code - look in the OTN library
    MArk

  • Encoded double byte characters string conversion

    I have double byte encoded strings stored in a properties file. A sample of such string below (I think it is japanese):
    \u30fc\u30af\u306e\u30a2
    I am supposed to read it from file, convert it to actual string and use them on UI. I am not able to figure how to do the conversion -- the string contains text as is, char backslash, char u, and so on. How to convert it to correct text (either using ai::UnicodeString or otherwise)?
    Thanks.

    Where did this file come from? Some kind of Java or Ruby export? I don't think AI has anything in its SDK that would natively read that. You could just parse the string, looking for \u[4 characters]. I believe if you created a QChar and initialized it with the integer value of the four-character hex string, it would properly create the character.

  • Long Conversion Time?

    Hello!
    I recently filmed a performance for my local theater and im in charge of producing DVD's. I shot in HDV using a Sony HDR HC3 and edited natively in Final Cut Pro (current version) running OSX 10.5.4. When i was finished i exported using the same settings leaving make movie self contained unchecked. I then imported the resulting HDV file into Compressor and gave it DVD Best Quality 90 minutes. I changed the Deinterlace to Better (Motion adaptive). Then i submit.
    The time for conversion started at about 5 minutes. After the status bar got halfway towards completion however, the time jumped to 26 hours! This can't seem right! I tried again this time checking the Making Move Self Contained box.. but i get the same result! I don't think it should take this long to convert to a DVD format. Especially since the video in only about 40 minutes long.
    Does anyone have any ideas? Thanks..
    System Specs: 2.4 ghz Alum iMac with 320gb internal and 500gb fw 800 for video editing. 3 gb ram 256 mb video card. Any other info just ask!
    Thanks!
    Dan

    Good day Dorcas,
    The length of time for the conversion really depends on the complexity of the file. 
    Kind regards,
    David
    Adobe Systems

  • Is there a way to scroll long conversations quickly?

    I keep some long running conversations in my Messages and sometimes want to actually call the sender. Is there a single small gesture to scroll up to the top of the conversation quickly so I can access the Call or Contact icon?

    Great!  Just have to get my pudgy fingertip all the way up there and presto ... thanks!!!

  • I have doubt regarding the byte to integer conversion.

    In java card epurse application the output we see is in bytes.to convert this byte to integer which is understandable by the end-user what should be done?

    809295 wrote:
    In java card epurse application the output we see is in bytes .
    to convert this byte to integer which is understandable by the end-user what should be done?What do you mean by we ?
    How many bytes ?
    On a java card platform support for integer is optional, you may only have short.
    I assume by understandable by the end-user you mean display as a sequence of decimal digits ?
    So two bytes 0x04 0xd2 (combined to a short 0x04d2 which is 1234 decimal)
    should be presented to the user as 0x31 0x32 0x33 0x34 (ascii values for '1' '2' '3' '4').

  • D7000 H.264 to ProRes - Ridiculously long conversion times

    When converting the D7000 footage from h.264 to ProRes for editing in Final Cut, it's taking absolutely ridiculously long to do so, even with short clips. I primarily use the Canon 7D. When converting 7D footage with those same output settings, it's acceptable the time it takes. But, with the D7000's footage, it's then astronomically longer of a process.
    Does anyone know why? I'm assuming it has to do with the higher compression of the Nikon footage, but I wanted to see if there is anymore light to be shed on this.
    Thanks in advance for taking time to read through this.
    Evan

    Shooting on the D7000, I used Image Capture to import a 2 minute 1080p24 clip that was 325 megs,
    Compressor processed it to ProRes422LT using 7 of my 8 cores in about 7 minutes to a file that is now 1.2 gigs.
    So, roughly, I'm looking at 6-8 times real time to process H,264 to ProResLT into a file that is roughly 4x the size of the  original.
    The image is lovely but shooting through my Nikkor primes has several negative aspects, most notably, today's autofocus lenses have focus barrels that go through the entire range in 120 to 200 degrees. My ancient manual Nikkors had focus rings that used 200 to more than 360 degrees of rotation to go from minimum focual distance to infinity. This, in combination with a split image rangefinder or microprism, meant precision focus was easy to achieve on the older lenses. Today's lenses have tolerances that are too tight for manual focus, merely letting go of the focusing barrel pushes the lens past the exact focus point. Of course, a precision focusing aid is not an option on any of Nikon's "professional" cameras these days.
    Auto focus tracking while shooting is unreliable and unprofessionally lame. Manually tracking focus while shooting requires a very good monitor hood/magnifier. This requirement alone makes the whole DSLR video thing totally stupid and completely amateurish. Even though I scored a new camera, I'm stuck with this lame process because some pinhead at my company has suddenly decided bokeh is cool.
    Why doesn't Nikon just adapt their CMOS, lens mount and basic controls to a dedicated, fully professional digital cinema camera?
    bogiesan

  • Byte to String conversion for encryption and decryption

    Hi Friends ,
    I am trying to encrypt a password string and then decrypt it .
    The thing is i need to convert the encrypted String which is a byte array to a string . While decrypting i need to convert the encrypted string to a Byte .
    I tried using String.getBytes() for converting a string to byte array , but this is giving an exception
    javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipherPlease find below my code
    import java.security.Key;
    import javax.crypto.Cipher;
    import javax.crypto.KeyGenerator;
    import sun.misc.BASE64Encoder;
    import sun.misc.BASE64Decoder;
    * @author rajeshreddy
    public class Encrypt
        public static void main(String[] args)
            try
            BASE64Encoder en = new BASE64Encoder();
            BASE64Decoder en1 = new BASE64Decoder();
                String password = "S_@!et";
                KeyGenerator kg = KeyGenerator.getInstance("DESede");
                Key key = kg.generateKey();
                Cipher cipher = Cipher.getInstance("DESede");
                cipher.init(Cipher.ENCRYPT_MODE, key);
                // Encrypt password
                byte[] encrypted = cipher.doFinal(password.getBytes());
                String e = new String(encrypted);
                byte[] toDecrypt  = e.getBytes();
                // Create decryption cipher
                cipher.init(Cipher.DECRYPT_MODE, key);
                byte[] decrypted = cipher.doFinal(toDecrypt);
                // Convert byte[] to String
                String decryptedString = new String(decrypted);
                System.out.println("password: " + password);
                System.out.println("encrypted: " + encrypted);
                System.out.println("decrypted: " + decryptedString);
            } catch (Exception ex)
                ex.printStackTrace();
    }I cab use sun.misc.BASE64Decoder and sun.misc.BASE64Encoder which avoids this error, but this packages are sun proprietery packages so there is a chance of removing these in future releases.
    Please suggest me the best way to tackle this

    1) The "Jakarta Commons Codec" project has Base64 and Hex encoders that are well tested and well regarded. Google is your friend.
    2) Since this is a new project, you should use AES rather than DESede.
    3) The defaults when generating the Cipher object using
    Cipher cipher = Cipher.getInstance("DESede");
                is for ECB block mode with PKCS5 padding. ECB is not a good block mode since it allows some limited forgery though splicing of ciphertext. Use one of the feedback modes such as CBC.
    4) Why are you encrypting passwords rather than just hashing them? While there are situations where encryption rather than hashing is required, it is not the norm and does normally require justification.
    5) Converting encrypted or hashed data to a String is not normally required. What are you doing with that requires this?
    Edited by: sabre150 on Dec 29, 2008 7:44 AM

  • Loosing prefixed zeros in byte to hexa conversion

    hi,
    i am using:
    Integer.toHexString(byte & 0xff) to convert from byte to hexadecimal.
    if the byte has zeros prefixed , they are being lost.
    ie. if the byte is 02 i get only 2. but i need the 02 as a whole.
    how can i correct this.
    10q.

    Don't create new threads with the same question:
    http://forum.java.sun.com/thread.jspa?threadID=601733

  • Byte b = new Byte((byte)in.read()); conversion error

    Hi
    I receive with a DataInputStream with:
    Byte b = new Byte((byte)in.read());
    If i send bytes < 0x79 or > 0xa0 all works, otherwise I obtain, i.e:
    0x80 = -84 (right)
    0x81 = -3
    0x82 = 26
    Why???

    In sender side seems ok, in dump file the bytes are ok; this is sender side (dataSend is a LinkedList):
    for (Iterator iter = dataSend.iterator(); iter.hasNext();) {  
    Byte b = (Byte)iter.next();
    bytePark = b.byteValue();
    dataOut.write(bytePark);
    // then I dump bytePark on file
    receiver side:
    BufferedReader in = new BufferedReader(
         new InputStreamReader(client.getInputStream()));
    Byte e = new Byte((byte)in.read());
    if (e.byteValue() == (byte)0xf3) { // I need analize when receive 0xf3
    // here e.byteValue() has wrong behavior

  • Converting byte[] to short, long, etc.

    I need to packetize the data with my own header embedded in the data. The header field is composed of data types: short, byte, and long. Since the header will be transported over the network using UDP socket, it will have to be converted to type byte[].
    Is there a clean way to convert from byte[] to short, and long data types? Or do I have to concatenate bytes and type cast them? How do I even type cast byte[] to short? Thanks.

    Have a look at the ByteBuffer class. You can wrap a byte
    array in such a buffer and write other types (like ints or longs etc)
    to the byte array through the buffer. Of course you can read those
    values back again using the buffer.
    kind regards,
    Jos

Maybe you are looking for

  • Issue in Report output

    Issue in Report output I am facing strange issue. I have created a BEx query and Executed in Bex analyser. In this output I can able to see * mark as values instead of KF. Anyone can help me in this.

  • Email marked as read on outlook without actually reading

    Hi, When I get an email in outlook it shows as unread. Once the email is sent to my blackberry the status on outlook changes to read (even without me ever opening the email on outlook or the blackberry). How can I stop this? I did a lot of research b

  • I cannot start PSE 10 clicking on the icons.

    I could not start PSE 10 clicking on the icons so I uninstalled it and reinstalled it.  I started up once and then won't start again.

  • User exit to get Calday from Calmonth to populate Key Date

    Gurus we have a requirement to populate key date using exit variable where the user is going to fill in the Calmonth and the last day of the month should go to Key date at query run time. Would you please advise the sample code I can write to achieve

  • Multi Schema to single schema.

    Hi, I am new to streams. Can it be possible to push the changes from multi schemas to a single schema? Structure for the consolidated schema will be same as other source schemas. Juast an additional column in target tables. I would like populate a un