in Education by
I am developing a software in Android. In a particular portion of software, I need to convert short to byte and re-convert to it to short. I tried below code but values are not same after conversion. short n, n1; byte b1, b2; n = 1200; // short to bytes conversion b1 = (byte)(n & 0x00ff); b2 = (byte)((n >> 8) & 0x00ff); // bytes to short conversion short n1 = (short)((short)(b1) | (short)(b2 << 8)); after executing the code values of n and n1 are not same. Why? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I did not get Grahams solution to work. This, however do work: n1 = (short)((b1 & 0xFF) | b2<<8);

Related questions

0 votes
    I am developing a software in Android. In a particular portion of software, I need to convert short to byte and re-convert to it ... short n1 = (short)((short)(b1) | (short)(b2...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am developing a software in Android. In a particular portion of software, I need to convert short to byte and re-convert to it ... short n1 = (short)((short)(b1) | (short)(b2...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    Which of these classes are used by Byte streams for input and output operation? (a) InputStream (b) ... Applets of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Which of these is a super class of wrappers Byte and short wrappers? (a) Long (b) Digits (c) ... java programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Q. 8 What is the short name of binary math? O Mega Byte O bit O Kilo Byte O Byte Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    Why can't you run java byte code on Android?...
asked Jan 14, 2021 in Technology by JackTerrance
0 votes
    I have to Update the Xml document object generated using Apache XMLbeans.There are two ways I am trying to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I'm trying to create a local temp bigquery table in memory for testing purposes. I'm doing this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    My question is a bit complicated and I wasted whole day without any good effect I get from one place ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    What is the difference between length() and size() of ArrayList? (a) length() and size() return the ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    What are the initial capacity and load factor of HashSet? (a) 10, 1.0 (b) 32, 0.75 (c) 16, 0. ... - The Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    What is the difference between TreeSet and SortedSet? (a) TreeSet is more efficient than SortedSet (b) SortedSet ... Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
...