Question: For the following java code, can someone explain what it is stating? String shortToHex(short x) { String ans=; for (int i=0; i <4; i++) {
For the following java code, can someone explain what it is stating?
String shortToHex(short x) { String ans=""; for (int i=0; i<4; i++) { int hex = x & 15; char hexChar = "0123456789ABCDEF".charAt(hex); ans = hexChar + ans; x = (short)(x >> 4); } return ans; }
String shortToBinary(short x) { String ans=""; for(int i=0; i<16; i++) { ans = (x & 1) + ans; x = (short)(x >> 1); } return ans; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
