S
S
Sergey Semenko2016-06-08 15:54:44
Java
Sergey Semenko, 2016-06-08 15:54:44

What operation can perform this action?

There are two values ​​in binary:

------------------------------101111111001001010111010011 (int)
100010000000000000000000100000101111111001001010111010011 (long)

Which operation can get the second value from the first?
PS The first value can be obtained by converting long -> int
. I managed to do this:
String value = "101111111001001010111010011";
String result = Long.toString(0x1100001L << 32 | Integer.parseInt(value, 2), 2);

It works, but is it correct?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fat Lorrie, 2016-06-08
@abler98

In the first value, there is obviously less information than in the second => no way.
UPD:
ideone.com/dNCxZU

long low = 0b101111111001001010111010011L;
long high = 0b100010000000000000000000100000L;
int moveSize = Long.toBinaryString(low).length();

long result = low + (high << moveSize);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question