I able to convert 1 of the int to boolean but not all ... Who can help ?
How can I convert the content in a csv from a int to boolean ?
Started by xxxxjayxxx, Apr 04 2011 07:58 AM
6 replies to this topic
#1
Posted 04 April 2011 - 07:58 AM
|
|
|
#2
Posted 04 April 2011 - 08:01 AM
something like:
mybool = (myint != 0)
?
mybool = (myint != 0)
?
#3
Posted 04 April 2011 - 08:03 AM
WingedPanther said:
something like:
mybool = (myint != 0)
?
mybool = (myint != 0)
?
Or !!myint if it is allowed.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#4
Posted 04 April 2011 - 08:04 AM
yea I try that ... but the content in my csv file is 1110000100 ... I want the result to be true true true false false false etc ... not just true only ...
#5
Posted 04 April 2011 - 10:13 AM
?????? Any pro can help ?????
#6
Posted 04 April 2011 - 10:42 AM
Assuming you're using 32 bit integers:
// Integer containing values to test is assumed to be called 'myint'
final int maxbits = 32;
boolean[] mybools = new boolean[maxbits];
for (int i = 0; i < maxbits; i++) {
mybools[i] = (myint & Math.pow(2, i)) != 0;
}
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#7
Posted 06 April 2011 - 08:13 AM
Why convert to int when you can use the string. Just loop through every character in the string, you save yourself the conversion
And then you can read them with
String content = "11110101011101101";
int len = content.length();
boolean[] bools = new boolean[len];
for (int i = 0; i < len; i++) {
if (content.charAt(i) == '0')
bools[i] = true;
else
bools[i] = false;
}
And then you can read them with
for (boolean b: bools) System.out.println(b);
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









