#Bit-Operation

1 messages · Page 1 of 1 (latest)

weak crypt
#

im trying to solve this task.
so far i converted the right-expression of xor into

1010 1010

2
0010 1010

my problem lies in the left-expression

when i convert 0x99 into decimal i get 153.

how am i supposed to shift 2 = 0010
153 positions to the left ?

misty meadowBOT
#

<@&987246399047479336> please have a look, thanks.

urban abyss
#

its the other way around

#

you shift 0x99 to the left twice

weak crypt
#

realy ?
0xaa is 170
so i shift 2 170 times to the right ?

urban abyss
#

no, you shift 0xaa to the right twice

#

the left side of <</>> gets shifted by the amount specified on the right side

#

left << right

weak crypt
#

is the amount of shifts not in the position after the arrow ?


#

___ <<

shadow adder
#

no

#

otherwise both would do the same thing

weak crypt
#

32

#

is the correct answer

#

yey

#

what would i do without you two

#

😂

urban abyss
#

all good

#

problem was just a misunderstanding of the syntax

weak crypt
#

yup

#

are you bachelor students ?

urban abyss
#

no

#

I just finished school

weak crypt
#

wow so you are young ?

urban abyss
#

kinda?

#

im 18

weak crypt
#

well 32 is wrong xD

#

14 is right

shadow adder
#

guys

weak crypt
#

i did && instead of XOR lol

shadow adder
#

you know you can just run the code right ?

weak crypt
#

its a test, i must do it on paper

misty meadowBOT
#
Alathreon's result

Snippets

Snippet 30, VALID

(0x99<<2)^(0xaa>>2)```
jshell> `590`
## System out
[Nothing]
shadow adder
urban abyss
weak crypt
#

yes online test.
similar tasks will probably be in the exam

#

i cant use IDE there

shadow adder
#

if it is a test we can't help you any longer

urban abyss
#

you are not supposed to run the code, instead the task is to understand these

urban abyss
#

just not spoonfeeding

weak crypt
shadow adder
urban abyss
#

its not?

urban abyss
#

seems like they are learning for it

weak crypt
#

im converting the hex numbers to decimal

#

and then into binary

#

on paper

#

and manually solving the expression on paper

#

but im not sure why it says
char a ?

#

one char has 1 byte

#

and 14 has 4 bit

#

14 would also be the solution for int a ?

shadow adder
weak crypt
#

one char has 2 byte ?

#

thats 2^8

#

8bit = 1 byte

#

or no ?

shadow adder
#

no

urban abyss
misty meadowBOT
#
Alathreon's result

Snippets

Snippet 23, VALID

(int)Character.MAX_VALUE```
jshell> `65535`
## System out
[Nothing]
shadow adder
#

you know that they are constants for this right ?

shadow adder
weak crypt
#

are there definition differences ? because for C it says char has one byte

shadow adder
#

In C yes

#

but java is a different language from C

weak crypt
#

🤯

#

ok learned something new

shadow adder
#

...

#

also

#

isn't char size unspecified in c ?

#

actually it seems to be specified as one byte

weak crypt
#

one byte

shadow adder
#

one of the few primitives that has a fixed size

#

compared to c where size may be random

#

in java, all primitives are totally defined

#

all primitives except boolean and char are signed

#

byte is one byte
short and char are two bytes
int and float are four bytes
long and double are height bytes

#

and note that those sizes are what you can put inside, their actual size in the computer is undefined

#

@weak crypt

#

@weak crypt also, do you know why java char is two bytes ?

weak crypt
#

not sure because ascii only needs 7 bits to display all characters

#

that means 8 bit sounds better

#

maybe to display additional characters ?

shadow adder
#

ascii isn't near enough

weak crypt
#

japanes letters ? 😄

shadow adder
#

and well, yes it's enough to display most english characters

#

but it can't display characters from any other language

#

like é in french

#

or whatever other language have

shadow adder
#

and then you also have symbols

#

like math symbols

#

or country symbols

#

and then you have emojis

#

which yes are characters

#

so in order to display all characters in utf8, you need 4 bytes

#

and while java knew that they needed more than one byte to make it work
I don't think they predicted that it would actually take 4 bytes pepekek

#

so anyway

#

c's char is bad
java's char is better but still meh

#

because the correct answer was 4

#

-_-

#

ah and just so you know

#

characters that are often used but maybe not in english are usually on two bytes

#

and weird characters like emojis are on four bytes

#

@weak crypt

weak crypt
#

are you a student ?

#

or have an academic

#

grade

shadow adder
#

I'm doing a master

weak crypt
#

coool

#

do logical operators work on integers ?

#

i think they dont

#

ah k

#

0 interpreted as false

#

anything else as true

shadow adder
#

it shouldn't compile

weak crypt
#

don't ? xD

shadow adder
#

but you marked this channel as java

urban abyss
#

looks like c to me

shadow adder
#

so I assume you are talking about java

weak crypt
#

ahh sry

shadow adder
#

well

weak crypt
#

i think i need to switch channels for c specific questions

shadow adder
#

actually no

#

my bad

urban abyss
#

lmao

#

it can be, but its missing context

weak crypt
#

are c questions also good in this channel ?

#

im doing a bit

#

c

#

java tasks are done

#

for now

shadow adder