类 BinaryStdOut
- java.lang.Object
-
- edu.princeton.cs.algs4.BinaryStdOut
-
public final class BinaryStdOut extends java.lang.Object
Binary standard output. This class provides methods for converting primtive type variables (boolean
,byte
,char
,int
,long
,float
, anddouble
) to sequences of bits and writing them to standard output. Uses big-endian (most-significant byte first).The client must
flush()
the output stream when finished writing bits.The client should not intermix calls to
BinaryStdOut
with calls toStdOut
orSystem.out
; otherwise unexpected behavior will result.
-
-
方法概要
修饰符和类型 方法 说明 static void
close()
Flushes and closes standard output.static void
flush()
Flushes standard output, padding 0s if number of bits written so far is not a multiple of 8.static void
main(java.lang.String[] args)
Tests the methods in this class.static void
write(boolean x)
Writes the specified bit to standard output.static void
write(byte x)
Writes the 8-bit byte to standard output.static void
write(char x)
Writes the 8-bit char to standard output.static void
write(char x, int r)
Writes the r-bit char to standard output.static void
write(double x)
Writes the 64-bit double to standard output.static void
write(float x)
Writes the 32-bit float to standard output.static void
write(int x)
Writes the 32-bit int to standard output.static void
write(int x, int r)
Writes the r-bit int to standard output.static void
write(long x)
Writes the 64-bit long to standard output.static void
write(short x)
Writes the 16-bit int to standard output.static void
write(java.lang.String s)
Writes the string of 8-bit characters to standard output.static void
write(java.lang.String s, int r)
Writes the string of r-bit characters to standard output.
-
-
-
方法详细资料
-
flush
public static void flush()
Flushes standard output, padding 0s if number of bits written so far is not a multiple of 8.
-
close
public static void close()
Flushes and closes standard output. Once standard output is closed, you can no longer write bits to it.
-
write
public static void write(boolean x)
Writes the specified bit to standard output.- 参数:
x
- theboolean
to write.
-
write
public static void write(byte x)
Writes the 8-bit byte to standard output.- 参数:
x
- thebyte
to write.
-
write
public static void write(int x)
Writes the 32-bit int to standard output.- 参数:
x
- theint
to write.
-
write
public static void write(int x, int r)
Writes the r-bit int to standard output.- 参数:
x
- theint
to write.r
- the number of relevant bits in the char.- 抛出:
java.lang.IllegalArgumentException
- ifr
is not between 1 and 32.java.lang.IllegalArgumentException
- ifx
is not between 0 and 2r - 1.
-
write
public static void write(double x)
Writes the 64-bit double to standard output.- 参数:
x
- thedouble
to write.
-
write
public static void write(long x)
Writes the 64-bit long to standard output.- 参数:
x
- thelong
to write.
-
write
public static void write(float x)
Writes the 32-bit float to standard output.- 参数:
x
- thefloat
to write.
-
write
public static void write(short x)
Writes the 16-bit int to standard output.- 参数:
x
- theshort
to write.
-
write
public static void write(char x)
Writes the 8-bit char to standard output.- 参数:
x
- thechar
to write.- 抛出:
java.lang.IllegalArgumentException
- ifx
is not betwen 0 and 255.
-
write
public static void write(char x, int r)
Writes the r-bit char to standard output.- 参数:
x
- thechar
to write.r
- the number of relevant bits in the char.- 抛出:
java.lang.IllegalArgumentException
- ifr
is not between 1 and 16.java.lang.IllegalArgumentException
- ifx
is not between 0 and 2r - 1.
-
write
public static void write(java.lang.String s)
Writes the string of 8-bit characters to standard output.- 参数:
s
- theString
to write.- 抛出:
java.lang.IllegalArgumentException
- if any character in the string is not between 0 and 255.
-
write
public static void write(java.lang.String s, int r)
Writes the string of r-bit characters to standard output.- 参数:
s
- theString
to write.r
- the number of relevants bits in each character.- 抛出:
java.lang.IllegalArgumentException
- if r is not between 1 and 16.java.lang.IllegalArgumentException
- if any character in the string is not between 0 and 2r - 1.
-
main
public static void main(java.lang.String[] args)
Tests the methods in this class.- 参数:
args
- the command-line arguments
-
-