#what does the |= operator mean?
1 messages Β· Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Here is an AI assisted attempt to answer your question π€. Maybe it helps! In any case, a human is on the way π. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
means OR
The |= operator in Java is a bitwise OR assignment operator. It performs a bitwise OR operation between two operands and assigns the result to the left operand.
Here's an example:
int a = 5; // binary: 0101
int b = 3; // binary: 0011
a |= b; // equivalent to a = a | b, result: 7 (binary: 0111)
This operator can be useful for setting specific bits in an integer variable without affecting the other bits.
Useful links:
a = a | b; = a |= b;
gpt already answered that
you cannot do |= for float double String & Object
only the integrals is allowed
and you can't use | on any of them either
enum, short, byte, char, int, long
no, only integer like types
not enums
well they kinda x = x | 3.2; // ???
(with bit flags)
you are OR-ing
so 3 is 0011
that's a double, doesn't work on double
5 is 0101
nothing to do with enums
0011 | 0101 becomes 0111
oh
which is 7
no
not really
| means or
bitwise OR rather than logical OR
OR returns 1 if atleast one of bits is 1
so in the 2^1 there is atleast 1 of bits is 1
so it became 1
oh boy i am getting confused.
damn in college they dont teach us crap
therefore becomes 0111 (7)
oh
i added ???
because it doesn't make sense
wait 0111 is 7 in binary?
yes
trying to understand, my monkey brain is not used to this lol
OH WAIT
I REMEMBER
THAT IS UUHHH
BIT COUNTING
i saw that 3 years ago in highschool
never had to actually use it
binary is 2 digits
1 and 0
so for every bit
there's 2 bytes
Each position is a power of 2
so this is 2 bytes
no
2^8 = 256
oh nvm
didn't read the statement carefully
but yes
This is also how decimal works
1234 = 1*10^3 + 2*10^2 + 3*10^1 + 4*10^0
its 2 bytes
2 bytes ?
all of this info is really usefull thanks stack, you are a real one
and alathreon too
decimal bits? like 10, 20,etc,etc?
like binary
@rain whale
| means OR
| 1 0
1 1 1
0 1 0
& means AND
& 1 0
1 1 0
0 0 0
^ means XOR
| 1 0
1 0 1
0 1 0
~ means NOT
1 -> 0, 0 -> 1
decimal as of base 10
binary is base 2
ooooh ok ok
Binary is base 2
Octal is base 8
Decimal is base 10
hex is base 16
hexadecimal it's called
ye
i am curious about the last part
it goes down
so does that mean you start with the bigger number 'til 0?
on the times(n) i mean
just like binary
you start from right
which is power of 0
as soon you progress to left
you power based on how much position you moved to left
Decimal:
10^0 = 1
10^1 = 10
10^2 = 10.
10^3 = 1000
etc
Binary:
2^0 = 1
2^1 = 10
2^2 = 100
2^3 = 1000
etc
Same for all bases
wait
why 10ΒΉ is 1?

oh my god, with this new found knowledge i can make encrypted messages
or at least a better password
it is!
never knew how hexadecimal worked
people never teached it in college or highschool so
i am only a first year student after all
You count with 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Everything is the same
You apply the same rules except you have 16 digits
Btw
try to add 2 binary numbers or 2 hex numbers
yeah, it really helps to understand that all number systems, including decimal, work the same way
as in sum of digit * base^index
its all just working the same way
the same system that u used to add decimals can be used to add numbers in any other base
btw seconds and minutes are technically base 60, assuming each number is a digit, so you apply the same rules but in base 60
hours is base 24
so by just applying this knowoledge, you know how to do math with time
yes
because 60Β² would be 60 minutes which is one hour
since 60 seconds times 60 seconds?
oh wait
i think i am wrong
60 * 60 would be over than 1 hour
oh no i wasn't
i just phrased it like ass
60Β² is one hour
60 minutes
which is 3600 seconds
anyway, please try this
i'll try it rn!
trying to check both octals
sorry mixed terms
they just want to show u that manual addition in binary works the same way as u learned in school for decimals
so u do it right to left and have the "carry" when u go beyond max digit
so 1+1 is 10. meaning u write down 0 and carry a 1 over for the next digit to add
and so on
(every number system is a base 10 system)
so it's 20?
Base ten system
0
1
2
3
4
5
6
7
8
9
10 *
11
12
13
14
15
16
17
18
19
20 *
Base eight system
0
1
2
3
4
5
6
7
10 *
11
12
13
14
15
16
17
20 *
21
22
23
24
Base four system
0
1
2
3
10 *
11
12
13
20 *
21
22
23
30 *
31
32
33
100 *
101
102
103
110 *
Base two system
0
1
10
11
101
110
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
10000
10001
10010
it just defines how many different symbols u have available per digit
what the number means is always given the same way though
sum of digit * base^index
they wanted u to do it like in school
digit by digit from right to left
oooooooooooh
like, imagine adding two decimal numbers manually:
123
+ 862
-----
from right to left u add 3+2
5
985
0 and 1 goes to the left
as u now need to add whats called a carry digit
yeah. and the exact same system can be applied to do addition in binary or any other system
when u have 1+1 in binary u end up at 10
so thats a 0 and a 1 carries over
bc 1+1 would be 2 but that symbol doesnt exist in binary. so u need to advance to the next digit
similar to how after 9 u get 10 in decimal
bc 9 is the last symbol
10000000
in a base-4 system u would count 0, 1, 2, 3 and then advance the digit to 10, 11, 12, 13, 20, 21,...
and so on
its essentially all the exact same mechanics. always working the same way
for systems beyond decimal we kinda have to invent new symbols to count past 9 in a digit
and people came up with using the alphabet for that
so in a hexadecimal (base-16) system we for example count 0-9 and then A-F
and then advance the digit
no
but in theory u could use any symbol u want, as long as everyone understands it
i'll try it myself
the ancient mayas for example used a base-20 number system
11111111
01101001
+00110111
---------
10100000
@rain whale
thats ||10100000||
i feel illiterate
which is 160
i would do this if i'm subtracting binary
for the 11111111 btw (-1)
wait so 1+1 is 10
what is 1+1+1?

11
is it 100?
0 but carry 1
oh
for the other digit
u need to think about it as if its decimal, bc it works the same way
u count up a digit until u reach the max symbol
and then advance
rethink decimals
0, 1, 2,..., 9, 10, 11,...
ok so once it reaches decimal the extra 1 just stays got it
Before we dive into our lessons, lets get introduced to the Abacus terminology. If you do not already have an Abacus, click here to see some Abacus we recommend
https://learnabacusathome.com/resources
For worksheets to go along with this lesson, try a 7 day FREE trial at
https://members.learnabacusathome.com/membership-options
For comprehens...
binary: 0, 1, 10, 11, 100, 101, 110, 111,...
as soon as u would get the symbol 2 in decimal, that doesnt exist anymore and u need to advance a digit
if 1+1 is 10, 1+1+1 is the same as 1+1 = 10 + 1 so 11
just practice a bit and it will click and feel super natural
52A6F
+DE693
------
Try this now @rain whale
ok so, if 10 is A that means F is 15
so it would be something like
5211615
+1314693
try to not go decimal
do it digit by digit from right to left
in hex
stay in the base to understand how it works
omg its hex
F+3. start with that. thats 3 symbols above the maximum available symbol in hex
its simple itself
so u need to advance a digit
i just add hex
F+1 gives u 10
no need to turn it to decimal
as casting is extra step
197768
so u get the digit 2 and the 1 carries over
nnno
@rain whale here is a tip
52A6F
+ DE693
1
-------
2
so lets say
9 + 2
its 11 obvious
but
12
19 +
2 + 9 is 11
but you can't just add 11 as final result
so what you do
taking in consideration the extra 1 carried over right?
put down 1
and take the 1 as a carry
so 1 + 1 is 2
- the carry
3
31
but u should stay in the base at hand and not switch to decimal to actually understand it
do the same step for hex
i would put 1 up to know its carry
1
52A6F
+ DE693
-------
2
1 carried over and 6 down?
its just clearer for me
im not sure which part is unclear to u
well whats F + 3
can u tell us what ur doing instead of just throwing out a result
i also feel like ur not reading everything people write, so maybe its just too much at once?
so
(we wrote it below in school. but whatever)
(we wrote it up) Β―_(γ)_/Β―
in school we used to wrote it up
Same in Greece, and for multiplication on the side
F + 3
is 0x12
but you can't add 2 digit at once
so you put 2
and 1 is a carry
1
52A6F
+ DE693
-------
2
now
what is 6 + 9
(never treat it as decimal ever)
it might help to add it in single steps. like 6 + 9 is the same as 6 + 1 + 1 + 1 + 1 +... (9 times)
why do u think that?
its really easy
6 + 1 + 1 + 1 + 1 + 1 + 1 +1 +1 +1
so 5 and 1 as a carry
wat
step by step
you know what i'll spoonfeed for once
next?
then C
wait so its F
G
no
that doesnt exist
^^
what do we do in a number system when we are out of symbols?
we advance the digit
1
52A6F
+ DE693
-------
02
so everything over 9 is gonna be 10 if its out of symbols?
well not ten
0 and 1 carried?
no
@rain whale what would happen if you add 1+9
(in decimal))
everything beyond the last available symbol will cause a new digit to be added
10
see
just that in hex we have more symbols per digit
after F comes 10
then 11 then 12... 19, 1A, 1B,...1F
then 1A
and then out of symbols again
i would say 0x10
ok i think i finally get it
20, 21
so i can its hex
which is 30
yes
and then so on
11
wait so now it's 11 again
gg
11 again the next one btw
it has the carry, cuz after F comes 10
5 + D should be 14 counting the carry
gg
again
it stays, no more carry
and what is 131102 in decimal now?
1 * 16^5
+ 3 * 16^4
+ 1 * 16^3
+ 1 * 16^2
+ 0 * 16^1
+ 2 * 16^0
and thats how it all works π
with that knowledge u could now also work with maya numbers
this is for example
7 * 20^2
+ 8 * 20^1
+ 9 * 20^0
which would be how the mayas wrote the number we know as 2969
143
?
no
i gave u the solution already
oh wait
u added it up
dunno, i didnt put it into a calc
but i doubt
it must be much higher
16^5 is already over a million
somehow python gave that
oh dang
it is, it's 1.048.576 mill
yeah but u need to add it all up
1 * 16^5
+ 3 * 16^4
+ 1 * 16^3
+ 1 * 16^2
+ 0 * 16^1
+ 2 * 16^0
1048576
- 196608
- 4096
- 256
- 0
- 2
i got bamboozled by google calculator
smells like it might be right
right. so that's how it all works. now u can in theory do everything u want with any number system u want
bc u understand the actual mechanics behind it
π
ok so let me get this straight, so i turned hex into decimal?
my monkey brain is confused of what i've just done but i think i start to get it
the last thing we did?
when you mention the binary numbers are you refering to the 0's and 1's right?
with the 1 million?
so what we did here is to learn how to turn anything into decimal
for that, let's quickly look at decimal itself
lets say the number 372. how does it work, how do these 3 digits form the number three-hundred-seventy-two?
each digit contributes a certain value to the final number
from right to left, we start with digit 2
digit 2 contributes to the final value 2 * 10^0
(thats just 2)
then the digit 7
it contributes to the final value 7 * 10^1
surprise surprise, that's 70
finally the digit 3
it contributes to the final value 3 * 10^2
thats 300
so the final value is 300+70+2
if people knew we inject this to a rock mashed to dust and turned into glass with magic runes they wouldn't believe it
so we always take the digit and multiple it with the base to the power of the index
and then sum that up
for decimals this exercises sounds pointless but we can transfer it to any other base
ok so in simple monke term words, we took what we resolved and then we dissect it like a bug to get what makes the number, the number itself
so if we for example look at the nunber 521 in a base-7 system, then that number means in decimal the following:
from right to left
the digit 1 contributes 1 * 7^0
the digit 2 contributes 2 * 7^1
the digit 5 contributes 5 * 7^2
yes
A = 10 right?
i mean its not ten itself
but after 9 we run out of digits
until the next batch
so how can i turn a word into a binary?
which system are u in now?
a base 2 system
which number from which system into what system?
from hex to base 2 system
so for example the hex number E6 to binary?
yeah
for that u go to decimal first and then we learn how to turn decimal into another system
so E6 in decimal is what?
we just learned how it works
digit 6 contributes...
digit E contributes...
sum up
done
6 * 16^0
14 * 16^1?
yes. but E has what "worth" in decimal?
14
oh
each digit in a base-16 system have the worth of powers of 16
so yeah. i think its 230 in decimal?
yup
now u need to learn how to go from decimal to another number system
and for that u need to repeatedly divide by bases of the target number system
so E6 from hex is 230 in decimal. and now we want the binary of that
no wait
we havent learned that direction yet
from decimal to another system works by dividing powers
u want 230 in binary. binary is base-2. so we need powers of 2
u need to find the highest power of 2 that u can divide 230 with
lets try out some
10
2^6 u mean?
yes. 2^7 = 128. that is the highest power of 2 that still fits into 230
how often does it fit inside 230? (division with remainder)
the admin is teaching me wizardry, if i tell this to my gf she aint believing it lol
it fits in it once. remainder would be 102 (230- 1*128)
so. we now found out that the 7th digit must be 1
so our work in progress binary number is
1000000
or actually, the 8th digit bc 2^7 is the 8th digit, given that the first digit is 2^0
so our wip result is
1000 0000
(adding the space for readability)
anyways. from our number 230 we covered 128 now
we have 102 left to cover
same procedure again. find the highest power of 2 that fits into it
6
yes. 64 fits into it once, remainder is 38
so we found out that the digit responsible for 2^6 is 1 bc it fits into it once
our wip result is
1100 0000
and yes, 2^5 is next
fits into it once again. so wip result is
1110 0000
remainder is indeed 6
1111 100
whats her highest power of 2 that fits into 6
yes so we now need to set the digit responsible for 2^2
and then, the highest power is gonna be 1
since we are left with 2
and after that, 1111 100
wip result: 1110 0100
huh
u need to set the digits that correspond to the power u picked
so remainder now is 2. highest base that fits is 2^1
fits once
remainder 0
so we are done after this step and get:
1110 0110
the last 0 is 0 so we didn't took it
ok so we move from hex -> decimal -> binary
if u go base-17 instead of base-2 u divide by powers of 17
and check how often they fit
and same with binary to get into a bigger number
since decimals are technically bytes of data
yeah. its always the same mechanics
then add more alphabet to it
if u want a base 17 system then count to G
if u need a base 20 system then count to J
ooooooooooooooooooooooooooh
or invent totally new symbols, who cares as long as everyone understands what each symbols worth is
the mayas drew lines and points
instead of using numbers and alphabets
ok ok, so basically, the more words i use the bigger the base is
then that base is turned into decimal
and then that is turned into binaries
yes. the mayas had a base-20 system with 20 unique symbols for their digits
which we would typically represent with 0-9A-J
dude i am learning more on discord than in college
this is crazy
our teacher didn't teached us what even operators are
7,8,9
yeah. but its base 20
huh
so in decimal thats 2969
that's how the mayas wrote down what we know as 2969
they count from 0 to 19 on a single digit
using these unique symbols
and then they advance to the next digit
where they again have 20 symbols to put
its base-20
similar to how we count in hex from 0 to F
huh
now that i realize
it just looks like a ram localization graph
for every bit and byte, it's getting taller
^^ ultimately u can pick whichever symbol u want as long as everyone gets what they mean
for example, let's say u invent a number system that uses 3 symbols per digit
first symbol is πΆ
second symbol π±
third symbol π
then u could write down a number like πΆπππ± for example
to get that into decimal u just need to know the base (base-3 bc it uses 3 symbols per digit) and the worth of each symbol (dog is first symbol, worth 0. cat is second symbol, worth 1, mouse is third symbol, worth 2)
then it translates to
1 * 3^0
+ 2 * 3^1
+ 2 * 3^2
+ 0 * 3^3
27 in decimal
and counting in that system is
πΆ, π±, π
π±πΆ, π±π±, π±π,
ππΆ, ππ±, ππ,
π±πΆπΆ, π±πΆπ±,...