when converting int to binary, how to output it to 8 characters, currently it only displays 1 and less than 7 zeros
int x = 1; String bin = Integer.toBinaryString(x); System.Out.Println(bin);
Output example on 0000 0001
I'm not sure if this is what you mean, but what about something like
String.format("%8s", Integer.toBinaryString(1)).replace(' ', '0')
will generate 00000001
00000001
You can fill your binary string with zeros.
String bin = String.format("%8s", Integer.toBinaryString(x).replace(' ', '0');
, , < 8.
Source: https://habr.com/ru/post/1527532/More articles:PHP gets the largest number of three variables - phpHow to convert String to Drawable - androidWhat is the correct way to use the android.text.format.DateFormat.format method - androidjQuery selector all identifiers that are integers - javascriptSVG height element not dynamic? - htmlmvn release: run does not deploy release version - javaMultipeer audio streaming stops running in the background - objective-cOptimization of a simple pinball solver - performancehow to print variable name and value using scala macro? - scala-macrosОшибка компилятора QtPropertyBrowser при добавлении файла moc_objectcontroller.cpp в исходное дерево Visual Studio - propertiesAll Articles