Index: libcfa/src/iostream.cfa
===================================================================
--- libcfa/src/iostream.cfa	(revision fd35f766d8330dbd9ef0103e4c43118bc8a7bfcb)
+++ libcfa/src/iostream.cfa	(revision 7fd71c78421f70cc3bc380f8fbcb5eb62a273834)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Mar 11 14:35:35 2020
-// Update Count     : 860
+// Last Modified On : Mon Apr 20 21:55:00 2020
+// Update Count     : 912
 //
 
@@ -29,4 +29,6 @@
 #include <complex.h>									// creal, cimag
 } // extern "C"
+
+#include <bitmanip.hfa>									// fms
 
 
@@ -459,8 +461,6 @@
 \
 		if ( f.base == 'b' || f.base == 'B' ) {			/* bespoke binary format */ \
-			int bits;													\
-			if ( f.val == (T){0} ) bits = 1;			/* force at least one bit to print */ \
-			else bits = sizeof(long long int) * 8 - __builtin_clzll( f.val ); /* position of most significant bit */ \
-			bits = bits > sizeof(f.val) * 8 ? sizeof(f.val) * 8 : bits; \
+			int bits = high1( f.val );					/* position of most significant bit */ \
+			if ( bits == 0 ) bits = 1;					/* 0 value => force one bit to print */ \
 			int spaces = f.wd - bits;					/* can be negative */ \
 			if ( ! f.flags.nobsdp ) { spaces -= 2; }	/* base prefix takes space */ \
@@ -565,28 +565,73 @@
 				fmt2.flags.pad0 = fmt2.flags.nobsdp = true;	\
 				if ( f.base == 'b' | f.base == 'B' ) { \
-					if ( f.wd > 64 ) fmt.wd = f.wd - 64; \
-					if ( f.flags.pc && f.pc > 64 ) fmt.pc = f.pc - 64; \
-					fmt2.wd = 64; \
+					if ( fmt.flags.pc && fmt.pc > 64 ) fmt.pc -= 64; \
+					if ( fmt.flags.left ) { \
+						fmt2.wd = fmt.wd; \
+						if ( fmt2.wd <= 64 ) { \
+							fmt2.wd = 64; \
+						} else { \
+							if ( fmt.pc > 0 ) { \
+								fmt2.wd -= fmt.pc; \
+							} else { \
+								fmt2.wd = fmt.wd - high1( msig ); \
+							} /* if */ \
+							if ( ! fmt.flags.nobsdp ) fmt2.wd -= 2; \
+							if ( fmt2.wd < 0 ) fmt2.wd = 0; \
+							fmt2.flags.left = true; \
+							fmt.wd = 0; \
+						} /* if */ \
+						printf( "left %d %d %x\n", f.wd, f.pc, f.all ); \
+						printf( "left %d %d %x\n", fmt.wd, fmt.pc, fmt.all ); \
+					} else { \
+						fmt2.wd = 64; \
+						if ( fmt.wd > 64 ) fmt.wd -= 64; \
+						printf( "left %d %d %x\n", f.wd, f.pc, f.all ); \
+						printf( "left %d %d %x\n", fmt.wd, fmt.pc, fmt.all ); \
+					} /* if */ \
+					fmt2.pc = 64; fmt2.flags.pc = true;	\
+					printf( "left %d %d %x\n", fmt2.wd, fmt2.pc, fmt2.all ); \
 					(ostype &)(os | fmt | "" | fmt2); \
 				} else if ( f.base == 'o' ) { \
-					fmt.val = (unsigned long long int)fmt.val >> 2; \
-					if ( f.wd > 21 ) fmt.wd = f.wd - 21; \
-					if ( f.flags.pc && f.pc > 21 ) fmt.pc = f.pc - 21; \
-					fmt2.wd = 1; \
-					fmt2.val = ((msig & 0x3) << 1) + 1; \
-					(ostype &)(os | fmt | "" | fmt2); \
-					sepOff( os ); \
-					fmt2.wd = 21; \
-					fmt2.val = lsig & 0x7fffffffffffffff; \
-					(ostype &)(os | fmt2); \
+					if ( fmt.flags.pc && fmt.pc > 21 ) fmt.pc -= 21; \
+					if ( fmt.flags.left ) { \
+						fmt2.wd = fmt.wd; \
+						if ( fmt2.wd <= 21 ) { \
+							fmt2.wd = fmt2.pc = 16; fmt2.flags.pc = true; \
+						} else { \
+						} /* if */ \
+					} else { \
+						fmt.val = (unsigned long long int)fmt.val >> 2; \
+						if ( fmt.wd > 21 ) fmt.wd -= 21; \
+						if ( ! fmt.flags.nobsdp ) { if ( fmt.pc < fmt.wd ) fmt.wd -= 1; else fmt.pc -= 1; } \
+						fmt2.wd = 1; \
+						fmt2.val = ((msig & 0x3) << 1) + 1; \
+						(ostype &)(os | fmt | "" | fmt2); \
+						sepOff( os ); \
+						fmt2.wd = 21; \
+						fmt2.val = lsig & 0x7fffffffffffffff; \
+						(ostype &)(os | fmt2); \
+					} /* if */ \
 				} else { \
-					if ( f.flags.left ) { \
-						if ( f.wd > 16 ) fmt2.wd = f.wd - 16; \
-						fmt.wd = 16; \
+					if ( fmt.flags.pc && fmt.pc > 16 ) fmt.pc -= 16; \
+					if ( fmt.flags.left ) { \
+						fmt2.wd = fmt.wd; \
+						if ( fmt2.wd <= 16 ) { \
+							fmt2.wd = 16; \
+						} else { \
+							if ( fmt.pc > 0 ) { \
+								fmt2.wd -= fmt.pc; \
+							} else { \
+								fmt2.wd = fmt.wd - ceiling2( high1( msig ), 4 ) / 4; \
+							} /* if */ \
+							if ( ! fmt.flags.nobsdp ) fmt2.wd -= 2; \
+							if ( fmt2.wd < 0 ) fmt2.wd = 0; \
+							fmt2.flags.left = true; \
+							fmt.wd = 0; \
+						} /* if */ \
 					} else { \
-						if ( f.wd > 16 ) fmt.wd = f.wd - 16; \
-						if ( f.flags.pc && f.pc > 16 ) fmt.pc = f.pc - 16; \
 						fmt2.wd = 16; \
+						if ( fmt.wd > 16 ) fmt.wd -= 16; \
 					} /* if */ \
+					fmt2.pc = 16; fmt2.flags.pc = true; \
 					(ostype &)(os | fmt | "" | fmt2); \
 				} /* if */ \
Index: tests/manipulatorsOutput3.cfa
===================================================================
--- tests/manipulatorsOutput3.cfa	(revision 7fd71c78421f70cc3bc380f8fbcb5eb62a273834)
+++ tests/manipulatorsOutput3.cfa	(revision 7fd71c78421f70cc3bc380f8fbcb5eb62a273834)
@@ -0,0 +1,107 @@
+#include <fstream.hfa>
+int main() {
+    int128 x = 0xffff;
+    x <<= 64;;
+    x += 0xffff;
+    x = -x;
+    sout | x;
+    sout | sign(x);
+    x = -x;
+    sout | sign(x);
+    sout | nl;
+#if 1
+    sout | bin(x);
+    sout | upcase(bin(x));
+    sout | nobase(bin(x));
+    sout | wd( 95, upcase(bin(x)) );
+    sout | wd( 95,90, upcase(bin(x)) );
+    sout | wd( 25,30, upcase(hex(x)) );
+    sout | nl;
+
+    sout | oct(x);
+    sout | nobase(oct(x));
+    sout | wd( 45, upcase(oct(123)) );
+    sout | wd( 45,40, upcase(oct(123)) );
+    sout | wd( 40,45, upcase(oct(123)) );
+    sout | wd( 45, upcase(oct(x)) );
+    sout | wd( 45,40, upcase(oct(x)) );
+    sout | wd( 40,45, upcase(oct(x)) );
+    sout | left(wd( 45, upcase(oct(x)) )) | 'X';
+    int128 y = 123456789;
+    sout | left(wd( 45, 49, upcase(oct(y)) )) | 'X';
+    sout | nl;
+
+    sout | hex(x);
+    sout | upcase(hex(x));
+    sout | nobase(hex(x));
+    sout | wd( 45, upcase(hex(x)) );
+    sout | wd( 45,40, upcase(hex(x)) );
+    sout | wd( 45,49, upcase(hex(x)) );
+    sout | left(wd( 45, upcase(hex(x)) )) | 'X';
+    sout | left(wd( 45,40, upcase(hex(x)) )) | 'X';
+    sout | left(wd( 45,49, upcase(hex(x)) )) | 'X';
+
+    sout | nl | nl;
+
+    int128 divisor = 0x4b3b4ca85a86c47a;
+    divisor <<= 16;
+    divisor += 0x98a224000000000;
+
+    // base 10
+    sout | divisor;
+    sout | wd(2, divisor);
+    sout | wd(3, divisor);
+    sout | wd(10, divisor);
+    sout | wd(24, divisor);
+    sout | wd(38, divisor);
+    sout | wd(39, divisor);
+    sout | wd(40, divisor);
+    
+    sout | wd(40, 30, divisor);
+    sout | wd(40, 38, divisor);
+    sout | wd(40, 40, divisor);
+    sout | pad0(wd(40, divisor));
+    sout | pad0(sign(wd(40,divisor)));
+    
+    // base 2
+    sout | upcase(bin(divisor));
+    sout | wd(38, upcase(bin(divisor)));
+    sout | wd(40, upcase(bin(divisor)));
+    sout | wd(40, 38, upcase(bin(divisor)));
+    sout | wd(40, 30, upcase(bin(divisor)));
+    sout | pad0(sign(wd(40, 38, upcase(bin(divisor)))));
+    
+    // oct
+    sout | upcase(oct(divisor));
+    sout | wd(38, upcase(oct(divisor)));
+    sout | wd(40, upcase(oct(divisor)));
+    sout | wd(40, 38, upcase(oct(divisor)));
+    sout | wd(40, 30, upcase(oct(divisor)));
+    sout | pad0(sign(wd(40, 38, upcase(oct(divisor)))));
+    
+    // hex
+    sout | upcase(hex(divisor));
+    sout | wd(38, upcase(hex(divisor)));
+    sout | wd(40, upcase(hex(divisor)));
+    sout | wd(40, 38, upcase(hex(divisor)));
+    sout | wd(40, 30, upcase(hex(divisor)));
+    sout | pad0(sign(wd(40, 38, upcase(hex(divisor)))));
+
+    
+    sout | bin(divisor);
+    sout | upcase(bin(divisor));
+    sout | oct(divisor);
+    sout | hex(divisor);
+    sout | upcase(hex(divisor));
+    sout | nobase(bin(divisor)) | nobase(oct(divisor)) | nobase(hex(divisor));
+    sout | sign(divisor);
+    sout | -divisor;
+    sout | sign(-divisor);
+    sout | wd(2, divisor);
+    sout | wd(3,10,divisor);
+    sout | left(wd(40,divisor)) | 'X';
+    sout | left(sign(wd(40, divisor))) | 'X';
+    sout | left(sign(wd(0,40, divisor))) | 'X';
+    printf( "%-+1.40dX\n", 123456789 );
+#endif // 0
+}
