@@ -11,22 +11,22 @@ public static string Bits(sbyte value, bool spaces = true)
1111
1212 for ( int i = 0 ; i < 8 ; i ++ )
1313 {
14- result [ i ] = ( char ) ( ( ( ( uint ) value >> 7 - i ) & 1 ) + 48 ) ;
14+ result [ i ] = ( char ) ( ( ( ( uint ) value >> ( 7 - i ) ) & 1 ) + 48 ) ;
1515 }
1616
1717 return spaces ? new string ( result , 0 , 8 ) . Insert ( 4 , " " ) : new string ( result , 0 , 8 ) ;
1818 }
1919 public static string Bits ( short value , bool spaces = true )
2020 {
21- return Bits ( ( sbyte ) ( ( uint ) value >> 8 ) , spaces ) + ( spaces ? " " : "" ) + Bits ( ( sbyte ) value , spaces ) ;
21+ return Bits ( ( sbyte ) ( ( uint ) value >> 8 ) , spaces ) + ( spaces ? " " : string . Empty ) + Bits ( ( sbyte ) value , spaces ) ;
2222 }
2323 public static string Bits ( int value , bool spaces = true )
2424 {
25- return Bits ( ( short ) ( ( uint ) value >> 16 ) , spaces ) + ( spaces ? " " : "" ) + Bits ( ( short ) value , spaces ) ;
25+ return Bits ( ( short ) ( ( uint ) value >> 16 ) , spaces ) + ( spaces ? " " : string . Empty ) + Bits ( ( short ) value , spaces ) ;
2626 }
2727 public static string Bits ( long value , bool spaces = true )
2828 {
29- return Bits ( ( uint ) ( ( ulong ) value >> 32 ) , spaces ) + ( spaces ? " " : "" ) + Bits ( ( uint ) value , spaces ) ;
29+ return Bits ( ( uint ) ( ( ulong ) value >> 32 ) , spaces ) + ( spaces ? " " : string . Empty ) + Bits ( ( uint ) value , spaces ) ;
3030 }
3131
3232 public static string Bits ( byte value , bool spaces = true ) => Bits ( ( sbyte ) value , spaces ) ;
@@ -44,7 +44,7 @@ public static string Bits<T>(T value, bool spaces = true)
4444
4545 while ( sizeInBytes != 0 )
4646 {
47- result = result . Insert ( 0 , Bits ( * address , spaces ) + ( spaces ? " " : "" ) ) ;
47+ result = result . Insert ( 0 , Bits ( * address , spaces ) + ( spaces ? " " : string . Empty ) ) ;
4848
4949 address ++ ;
5050 sizeInBytes -- ;
@@ -55,13 +55,14 @@ public static string Bits<T>(T value, bool spaces = true)
5555 public static string Bits ( void * ptr , int bytes , bool spaces = true )
5656 {
5757Assert . IsNotNull ( ptr ) ;
58+ Assert . IsGreater ( bytes , - 1 ) ;
5859
5960 byte * address = ( byte * ) ptr ;
6061 string result = string . Empty ;
6162
6263 while ( bytes != 0 )
6364 {
64- result = result . Insert ( 0 , Bits ( * address , spaces ) + ( spaces ? " " : "" ) ) ;
65+ result = result . Insert ( 0 , Bits ( * address , spaces ) + ( spaces ? " " : string . Empty ) ) ;
6566
6667 address ++ ;
6768 bytes -- ;
@@ -81,11 +82,11 @@ public static string Hex(short value)
8182 }
8283 public static string Hex ( int value , bool spaces = true )
8384 {
84- return Hex ( ( ushort ) ( ( uint ) value >> 16 ) ) + ( spaces ? " " : "" ) + Hex ( ( ushort ) ( value & ushort . MaxValue ) ) ;
85+ return Hex ( ( ushort ) ( ( uint ) value >> 16 ) ) + ( spaces ? " " : string . Empty ) + Hex ( ( ushort ) ( value & ushort . MaxValue ) ) ;
8586 }
8687 public static string Hex ( long value , bool spaces = true )
8788 {
88- return Hex ( ( uint ) ( ( ulong ) value >> 32 ) , spaces ) + ( spaces ? " " : "" ) + Hex ( ( uint ) ( value & uint . MaxValue ) , spaces ) ;
89+ return Hex ( ( uint ) ( ( ulong ) value >> 32 ) , spaces ) + ( spaces ? " " : string . Empty ) + Hex ( ( uint ) ( value & uint . MaxValue ) , spaces ) ;
8990 }
9091
9192 public static string Hex ( byte value ) => Hex ( ( sbyte ) value ) ;
@@ -103,7 +104,7 @@ public static string Hex<T>(T value, bool spaces = true)
103104
104105 while ( iterations != sizeof ( T ) )
105106 {
106- result = result . Insert ( 0 , Hex ( * address ) + ( ( spaces && ( iterations != 0 ) && ( iterations % 2 == 0 ) ) ? " " : "" ) ) ;
107+ result = result . Insert ( 0 , Hex ( * address ) + ( ( spaces && ( iterations != 0 ) && ( iterations % 2 == 0 ) ) ? " " : string . Empty ) ) ;
107108
108109 address ++ ;
109110 iterations ++ ;
@@ -114,14 +115,15 @@ public static string Hex<T>(T value, bool spaces = true)
114115 public static string Hex ( void * ptr , int bytes , bool spaces = true )
115116 {
116117Assert . IsNotNull ( ptr ) ;
118+ Assert . IsGreater ( bytes , - 1 ) ;
117119
118120 byte * address = ( byte * ) ptr ;
119121 int iterations = 0 ;
120122 string result = string . Empty ;
121123
122124 while ( iterations != bytes )
123125 {
124- result = result . Insert ( 0 , Hex ( * address ) + ( ( spaces && ( iterations != 0 ) && ( iterations % 2 == 0 ) ) ? " " : "" ) ) ;
126+ result = result . Insert ( 0 , Hex ( * address ) + ( ( spaces && ( iterations != 0 ) && ( iterations % 2 == 0 ) ) ? " " : string . Empty ) ) ;
125127
126128 address ++ ;
127129 iterations ++ ;
0 commit comments