i am ran
my query is how to know the input value of integer is decimal or hexdecimal
Printable View
i am ran
my query is how to know the input value of integer is decimal or hexdecimal
Input from where?
for ex consider integer variables a,b
a='0x5a';
b=90;
here both are displays same values when print them
i want know the input of a is decimal or hexdecimal. input value is given by others it will not displays to the programer
With those quotes it won't compile at all.
If you remove the quotes then hexadecimals start with 0x or 0X.
Both values get stored in the same form (4 bytes for integer; base 16) and represented as an integer when you display it on the screen or in your code (not a decimal number!).
Code:int a = 0xF3;
int b = 243;
System.out.println(a);
if(a == b)
System.out.println("Equivalant!");
if(0x000000F3 == 243)
System.out.println("Equivalant!");
my problem is that input is given by other programmer it is decimal or hexdecimal value .
i want to know that the given input value is decimal or hexdecimal. based on this i can solve the puzzle.
for ex he gives the input for integer variable is 0x5a it is hexdecimal value then i will divide it by rgb format and solve the puzzle.
if it is decimal it will be solved by another way
as r035198x asked "Input from where?"
If you input is the form of a string you can do something like this:
Code:int value = 0;
try
{
value = Integer.parseInt(input); //input is a string
}
catch(Exception e)
{
System.out.println("Not an Integer")
}
i will explain clearly
package test.blurimg;
public class BlurImage {
public image blur_image(image i, int radius) {
//Write your code here
return null;
}
// You could use this sample code to test your functions
// Following main fucntion contains 3 representative test cases
public static void main(String[] args) {
//TestCase 1
try {
image i = new image();
i.rows = 5;
i.columns = 3;
i.data = new int[][]{{6, 12, 18}, {5, 11, 17}, {4, 10, 16}, {3, 9, 15}, {2, 8, 14}};
BlurImage obj = new BlurImage();
image res = obj.blur_image(i, 2);
System.out.println("TestCase 1");
if (res != null) {
for (int k = 0; k < i.rows; k++) {
System.out.println();
for (int j = 0; j < i.columns; j++) {
System.out.print(res.data[k][j] + ",");
}
}
} else
System.out.println("NULL");
}
catch (Exception e) {
e.printStackTrace();
}
//TestCase 2
try {
image i = new image();
i.rows = 3;
i.columns = 5;
i.data = new int[][]{{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038}};
BlurImage obj = new BlurImage();
image res = obj.blur_image(i, 1);
System.out.println("\nTestCase 2");
if (res != null) {
for (int k = 0; k < i.rows; k++) {
System.out.println();
for (int j = 0; j < i.columns; j++) {
System.out.print(res.data[k][j] + ",");
}
}
} else
System.out.println("NULL");
}
catch (Exception e) {
e.printStackTrace();
}
//TestCase 3
try {
image i = new image();
i.rows = 3;
i.columns = 5;
i.data = new int[][]{{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038}};
BlurImage obj = new BlurImage();
image res = obj.blur_image(i, 4);
System.out.println("\nTestCase 3");
if (res != null) {
for (int k = 0; k < i.rows; k++) {
System.out.println();
for (int j = 0; j < i.columns; j++) {
System.out.print(res.data[k][j] + ",");
}
}
} else
System.out.println("NULL");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
this is my puzzle here i.data is input it contains both decimal and hexdecimal values
if i.data contains hexdecimal value it will converted into RGB format and solved.
otherwise i will solve by another way.
You have to understand, whether you represent your value as a hexdecimal or an integer, it's real value is exactly the same. There is no way to know the difference because there is no difference.
Where is the array data coming from?
Do you read it from a file? Do you receive it as an object or perhaps strings passed as program arguments?
This is the question that we have been asking and you have not answered.
if array contains hexdecimal value then it will in the form of RGB now i will divide it R,G,B and find the avg of r,g,b of surrounded values for a value.
if it is decimal i will find the avg of surrounded values for a value.
here i need to find out if array contains hexdecimal it will follow first case other wise second case
the solution for this puzzle will suitable for all input values like decimal and hexdecimal
here data is array of integers. they cannot allow using of strings.
we must follow the rules.
here we are using the given inputs only. i already posted them along with puzzle.
please refer them .
package test.blurimg;
public class image {
public int[][] data;
public int rows;
public int columns;
}
Convert your input to a string and check with the subString method if it contains an 'x' or any letters 'a-f'
Then integers are just integers.
The values are the same.
This has already been said before but you continue to ignore it.
in my puzzle i am passing the object to a function . object contains array of integers .
once when i assign a hexdecimal value to integer it will convert into binary format.
when i was trying to convert it into string it will gives a decimal value even if we are assign the hexdecimal values. "we cannot change the inputs. it is rule for this contest"
Are we also allowed to read responses posted to this thread?
Why do you post at all if you ignore the responses that you get?