Suppose I have a boolean array: -
-
boolean[] b = {true, true, false, false, true, true};
-
I want to convert it to a decimal number like a binary number. I this case the array represents number 110011 in decimal. So how do I convert the array to binary and then integer?
5 15041 JosAH 11,448
Recognized Expert MVP
Suppose I have a boolean array: -
-
boolean[] b = {true, true, false, false, true, true};
-
I want to convert it to a decimal number like a binary number. I this case the array represents number 110011 in decimal. So how do I convert the array to binary and then integer?
Hint, for the following numbers: 0, 1, 2, ... n think of this sequence instead:
1<<0, 1<<1, 1<<2 , ... 1<<n
kind regards,
Jos
I'm sorry, I don't know yet about the shift operators, what they do or what they are for. Can you please explain more?
ok, this is what i think u want to do, u want to have a array with integers like bynary so when u have true is 1 and false is 0.
well i can do this:
boolean[] b = {true, true, false, false, true, true};
int[] a = new int[b.lenght];
for(int i = 0; i <= b.lenght; i++){
if(b[i].equals(true)){
a[i] = 1;
}else{
a[i] = 0;
}
}
i think this is ok, sry if something wrong but i just delent de jDeveloper :P so i dont know if this java code its ok
PM if something wrong
bye
JosAH 11,448
Recognized Expert MVP
I'm sorry, I don't know yet about the shift operators, what they do or what they are for. Can you please explain more?
Ok, I'll rewrite my hint for you then: for the following numbers: 0, 1, 2, 3 ... n think
of this sequence instead: 2**0, 2**1, 2**2, 2**3, ... 2**n where '**' is my
notation for "raised to the power" (note '**' is not a Java operator).
kind regards,
Jos
ok, this is what i think u want to do, u want to have a array with integers like bynary so when u have true is 1 and false is 0.
well i can do this:
boolean[] b = {true, true, false, false, true, true};
int[] a = new int[b.lenght];
for(int i = 0; i <= b.lenght; i++){
if(b[i].equals(true)){
a[i] = 1;
}else{
a[i] = 0;
}
}
i think this is ok, sry if something wrong but i just delent de jDeveloper :P so i dont know if this java code its ok
PM if something wrong
bye
No, that is not OK. The OP does not want the binary notation, but rather the decimal value. And if(b[i].equals(true)){ will not compile, nor will b.lenght.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Shalini |
last post by:
Hi ,
Is the code below efficient??
bool *isElement(char **a1,long lengtha1,char **a2,long lengtha2){
charQuickSort(a2, 0, (lengtha2-1));
bool *tag=(bool*)calloc(lengtha1,sizeof(bool));
int...
|
by: Charles Law |
last post by:
I thought this had come up before, but I now cannot find it.
I have a byte array, such as
Dim a() As Byte = {1, 2, 3, 4}
I want to convert this to an Int32 = 01020304 (hex).
If I use...
|
by: Len via DotNetMonster.com |
last post by:
I have to set up a 2d array(13, 4) containing a deck of playing cards.
What I am wondering is how to correctly set up the array in the first
place, and then how do you access the information once...
|
by: Jason Heyes |
last post by:
What STL algorithm do I use to set all bool elements of an array to false in
just one line of code? Thanks!
|
by: Speed |
last post by:
Could you please tell me which is the most efficient of way writing a
BOOLEAN array to a file.
Thanks a ton.
Speed
| |
by: Speed |
last post by:
Could you please tell me which is the most efficient of way writing a
BOOLEAN array to a file.
Thanks a ton.
Speed
|
by: Learner |
last post by:
Hello,
I have database field called 'PullAHead' defined as a bit field.
Now if user doesn't pick a 'Yes' or 'No' in the front I need to be able
to send a null value into the 'PullAHead' field in...
|
by: The Midnighter |
last post by:
Alright, so basically here's what's supposed to happen.
It's an Airline reservation system, basically taking a row of 10 seats, 1 isle, 1 window. Yes, there's only one row. xD So 5 seats isle, 5...
|
by: Mary Seelye |
last post by:
I don't even know where to start with this or figure out how to get them to display. I need the first 25 to be true and the last 25 to be false.
I need all the trues and falses to display.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |