I want to change to value of the major and minor of my beacon by calling a shell script from a java code.
If for example I want to set the value of the Major to 39321
, I have to pass a string with the value 99 99
as parameter to the shell code.
If I want to set it to 34866
, I have to pass the hex code 88 32
.
How can I convert from a long number like the 39321 to this two character composed hex number like 99 99
?
Asked
Active
Viewed 1,835 times
0

Celiiine
- 19
- 5
-
Format it with "%x" is not enough ? – Serge Ballesta Jun 10 '16 at 09:33
-
Or `Long.toHexString`? – Jon Skeet Jun 10 '16 at 09:34
-
Long.toHexString will change 39321 to 0000000000000000000000000000003339333231 and not 99 99. "%x" is just for formatting it will also not change 39321 to "99 99" – Celiiine Jun 10 '16 at 09:45
-
See my answer here: http://stackoverflow.com/a/37709287/1461050 – davidgyoung Jun 11 '16 at 19:02
1 Answers
0
You can use toHexString(long i) method from Long class.
For example :
Long.toHexString(39321)
It returns a string representation of the long argument as an unsigned integer in base 16.

Necromancer
- 869
- 2
- 9
- 25
-
This will return 0000000000000000000000000000003339333231, I am expecting to have 99 99 as result. – Celiiine Jun 10 '16 at 09:52
-
@Celiiine I got String result **9999** when testing with my eclipse. I am using **jdk1.8.0_72** and running on window 8. – Necromancer Jun 10 '16 at 10:02