String val="0xa";//10
//next I am removing the "0x" in "0xa" for unhex() to work properly
String res[] = split(val, 'x');
if (res.length>=2 ) {
val=res[1];
} else
val="0";
int n=unhex(val);
println(val+" is "+n);
To find the most significant bit.... you need to elaborate more. The least significant is the one to the right in binary representation. The most significant will depend in your data structure. For example, a 32 bit integer's most significant bit would be bit 32. If you store a byte into an integer, would its most significant bit be bit number 8? So it depends on the data you are working on. Why do you need this info and how are you using it?
Actually what i am trying to do is bit phase slicing .
by getting the most ,least and middle significant bit of the pixels of the image .
And it will be very useful in case of steganography in order to hide any other image
Goto yes i know those function but the main problem is they take int as an
argument since it is showing the number format exception on changing to integer
so can't put String into it ;(
Answers
https://Processing.org/reference/hex_.html
https://Processing.org/reference/unhex_.html
I want to find the most significant bit
http://docs.Oracle.com/javase/8/docs/api/java/lang/Integer.html#highestOneBit-int-
One way to do it is (other elegant ways exists)
To find the most significant bit.... you need to elaborate more. The least significant is the one to the right in binary representation. The most significant will depend in your data structure. For example, a 32 bit integer's most significant bit would be bit 32. If you store a byte into an integer, would its most significant bit be bit number 8? So it depends on the data you are working on. Why do you need this info and how are you using it?
Kf
Actually what i am trying to do is bit phase slicing . by getting the most ,least and middle significant bit of the pixels of the image . And it will be very useful in case of steganography in order to hide any other image
Goto yes i know those function but the main problem is they take int as an argument since it is showing the number format exception on changing to integer so can't put String into it ;(
greyscale again, or packed ARGB value?
given a 32 bit int
using the ARGB value like this is probably not what you want though.
hex(value); give the 0xff or something like this and they all are string so we cannot do the shift operation in strings.
but https://processing.org/reference/unhex_.html
which was mentioned in the very first answer up there
NB this doesn't like any 0x or 0X at the start of that string so remove it if it's there