Index: calctool.c
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/calctool.c,v
retrieving revision 1.110
diff -u -r1.110 calctool.c
--- calctool.c	13 Sep 2006 18:03:53 -0000	1.110
+++ calctool.c	21 Sep 2006 21:12:43 -0000
@@ -95,6 +95,7 @@
                               "SCIENTIFIC" };
 char *Rtstr[MAXTRIGMODES] = { "DEG", "GRAD", "RAD" };
 char *Rsstr[MAXSYNTAX]    = { "ARITHMETIC", "ARITHMETIC_PRECEDENCE" };
+char *Rcstr[MAXBITCALC]   = { "NO_BITCALCULATING_MODE", "BITCALCULATING_MODE" };
 
 
 /* Valid keys when an error condition has occured. */
Index: calctool.h
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/calctool.h,v
retrieving revision 1.83
diff -u -r1.83 calctool.h
--- calctool.h	13 Sep 2006 18:03:53 -0000	1.83
+++ calctool.h	21 Sep 2006 21:12:43 -0000
@@ -76,7 +76,8 @@
 enum res_type { R_ACCURACY, R_BASE, R_DISPLAY, R_MODE, R_REGS, R_TRIG,
                 R_ZEROES,   R_TSEP, R_SYNTAX,  R_XPOS, R_YPOS,
                 R_REG0,     R_REG1, R_REG2,    R_REG3, R_REG4,
-                R_REG5,     R_REG6, R_REG7,    R_REG8, R_REG9
+                R_REG5,     R_REG6, R_REG7,    R_REG8, R_REG9,
+				R_BITCALC
 };
 
 enum trig_type { DEG, GRAD, RAD };          /* Trigonometric types. */
@@ -194,6 +195,7 @@
 #define MAXTRIGMODES   3          /* Maximum number of trig. modes. */
 #define MAXVKEYS       1          /* Number of valid keys after an error. */
 #define MAXSYNTAX      2          /* Number of syntaxes in calculator */
+#define MAXBITCALC     2          /* Choices for bitcalculating */
 
 #define MCOLS          8          /* Number of columns of "special" keys. */
 #define MROWS          2          /* Number of rows of "special" keys. */
@@ -372,6 +374,7 @@
     int started;       /* Set just before window is displayed. */
     int toclear;       /* Indicates if display should be cleared. */
     int warn_change_mode;    /* Should we warn user when changing modes? */
+    int bitcalculating_mode;  /* 0 = no, else yes */
 };
 
 typedef struct calcVars *Vars;
Index: extern.h
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/extern.h,v
retrieving revision 1.14
diff -u -r1.14 extern.h
--- extern.h	9 Jan 2006 16:30:20 -0000	1.14
+++ extern.h	21 Sep 2006 21:12:43 -0000
@@ -42,6 +42,7 @@
 extern char *Rmstr[];          /* Mode mode X resource strings. */
 extern char *Rtstr[];          /* Trig mode X resource strings. */
 extern char *Rsstr[];          /* Syntax resource strings. */
+extern char *Rcstr[];          /* Bitcalculating mode. */
 
 extern double max_fix[];       /* Maximum showable fixed values. */
 
Index: functions.c
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/functions.c,v
retrieving revision 1.84
diff -u -r1.84 functions.c
--- functions.c	13 Sep 2006 18:03:53 -0000	1.84
+++ functions.c	21 Sep 2006 21:12:44 -0000
@@ -254,7 +254,7 @@
 }
 
 
-static int 
+int 
 usable_num(int MPnum[MP_SIZE]) 
 {
     int ret = 0;
Index: functions.h
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/functions.h,v
retrieving revision 1.9
diff -u -r1.9 functions.h
--- functions.h	1 May 2006 17:26:26 -0000	1.9
+++ functions.h	21 Sep 2006 21:12:44 -0000
@@ -33,5 +33,6 @@
 void perform_undo(void);
 void perform_redo(void);
 void clear_undo_history(void);
+int usable_num(int MPnum[MP_SIZE]);
 
 #endif /*FUNCTIONS_H*/
Index: get.c
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/get.c,v
retrieving revision 1.45
diff -u -r1.45 get.c
--- get.c	6 Sep 2006 15:02:34 -0000	1.45
+++ get.c	21 Sep 2006 21:12:44 -0000
@@ -383,18 +383,36 @@
 
     if (get_str_resource(R_SYNTAX, str)) {
       for (i = 0; i < MAXSYNTAX; i++) {
-	if (EQUAL(str, Rsstr[i])) {
-	  break;
-	}
+		if (EQUAL(str, Rsstr[i])) {
+		  break;
+		}
       }
       
       if (i == MAXSYNTAX) {
-	FPRINTF(stderr, _("%s: invalid syntax mode [%s]\n"), 
-		v->progname, str);
+		FPRINTF(stderr, _("%s: invalid syntax mode [%s]\n"), 
+				v->progname, str);
       } else {
-	v->syntax = i;
+		v->syntax = i;
       }
     }
+	
+	v->bitcalculating_mode = 0; // default = off
+
+    if (get_str_resource(R_BITCALC, str)) {
+      for (i = 0; i < MAXBITCALC; i++) {
+		if (EQUAL(str, Rcstr[i])) {
+		  break;
+		}
+      }
+      
+      if (i == MAXBITCALC) {
+		FPRINTF(stderr, _("%s: invalid bitcalc choice [%s]\n"), 
+				v->progname, str);
+      } else {
+		v->bitcalculating_mode = i;
+      }
+    }
+
 
     if (get_bool_resource(R_REGS, &boolval)) {
         v->rstate = boolval;
Index: gtk.c
===================================================================
RCS file: /cvs/gnome/gcalctool/gcalctool/gtk.c,v
retrieving revision 1.202
diff -u -r1.202 gtk.c
--- gtk.c	6 Sep 2006 15:02:34 -0000	1.202
+++ gtk.c	21 Sep 2006 21:12:49 -0000
@@ -40,6 +40,7 @@
 #endif /*DISABLE_GNOME*/
 #include <gconf/gconf-client.h>
 #include "ce_parser.h"
+#include "mpmath.h"
 
 #define BUT_0_BAS     X->bas_buttons[16]       /* 0 - in "Basic" mode */
 #define BUT_1_BAS     X->bas_buttons[12]       /* 1 - in "Basic" mode */
@@ -216,6 +217,7 @@
 static void set_memory_toggle(int);
 static void set_show_tsep_toggle(int);
 static void set_show_zeroes_toggle(int);
+static void set_show_bitcalculating_toggle(int);
 static void set_win_position();
 static void show_ascii_frame();
 static void show_menu_for_button(GtkWidget *, GdkEventKey *event);
@@ -333,6 +335,8 @@
       N_("Show trailing zeroes"),     G_CALLBACK(mstz_proc), FALSE },
     { "Thousands", NULL, N_("Show T_housands Separator"), "<control>K",
       N_("Show thousands separator"), G_CALLBACK(ts_proc),   FALSE },
+    { "Bitcalculating", NULL, N_("Show Bitcalculating _Extension"), "<control>E",
+      N_("Show bitcalculating extension"), G_CALLBACK(mb_proc),   FALSE },
     { "Memory",    NULL, N_("_Memory Registers"),         "<control>M",
       N_("Show memory registers"),    G_CALLBACK(mb_proc),   FALSE },
     { "Show",      NULL, N_("Show _Trailing Zeroes"),     "<control>T",
@@ -399,6 +403,7 @@
 "      <separator/>"
 "      <menuitem action='Trailing'/>"
 "      <menuitem action='Thousands'/>"
+"      <menuitem action='Bitcalculating'/>"
 "      <separator/>"
 "      <menuitem action='Memory'/>"
 "      <separator/>"
@@ -695,13 +700,14 @@
             break;
 
         case exprs:
-	    {
-		struct exprm_state *e = get_state();
-		memcpy(&(e->button), n, sizeof(struct button));
-		new_state();
-		do_expression();
-	    }
-            break;
+		  {
+			struct exprm_state *e = get_state();
+			memcpy(&(e->button), n, sizeof(struct button));
+			new_state();
+			do_expression();
+			set_bit_panel();
+		  }
+		  break;
 
         default:
             assert(0);
@@ -2281,6 +2287,7 @@
     set_accuracy_toggle(v->accuracy);
     set_show_tsep_toggle(v->show_tsep);
     set_show_zeroes_toggle(v->show_zeroes);
+    set_show_bitcalculating_toggle(v->bitcalculating_mode);
 }
 
 
@@ -2601,7 +2608,6 @@
     return(button);
 }
 
-
 static void
 toggle_expressions()
 {
@@ -2677,7 +2683,11 @@
         handle_menu_selection(X->mrec[(int) M_RSHF], choice);
     } else if (EQUAL(name, "ArithmeticPrecedence")) {
         toggle_expressions();
-    }
+    } else if (EQUAL(name, "Bitcalculating")) {
+	  v->bitcalculating_mode = v->bitcalculating_mode ^ 1;
+	  set_mode(v->modetype);
+	  put_resource(R_BITCALC, Rcstr[v->bitcalculating_mode]);
+    } 
 }
 
 
@@ -3021,29 +3031,62 @@
 
 void
 set_bit_panel() {
-    int bit_str_len, i, MP1[MP_SIZE], MP2[MP_SIZE];
 
-    MPstr_to_num(v->display, v->base, MP1);
-    mpcmim(MP1, MP2);
-    if (mpeq(MP1, MP2)) {
-        char *bit_str, label[3], tmp[MAXLINE];
-        int toclear = (key_equal(v->current, KEY_CE)) ? TRUE : FALSE;
-
-        bit_str = make_fixed(MP1, tmp, BIN, MAXLINE, toclear);
-        bit_str_len = strlen(bit_str);
-        if (bit_str_len <= MAXBITS) {
+    switch (v->syntax) {
+    case npa:
+	  {
+		int bit_str_len, i, MP1[MP_SIZE], MP2[MP_SIZE];
+		
+		MPstr_to_num(v->display, v->base, MP1);
+		mpcmim(MP1, MP2);
+		if (mpeq(MP1, MP2)) {
+		  char *bit_str, label[3], tmp[MAXLINE];
+		  int toclear = (key_equal(v->current, KEY_CE)) ? TRUE : FALSE;
+		  
+		  bit_str = make_fixed(MP1, tmp, BIN, MAXLINE, toclear);
+		  bit_str_len = strlen(bit_str);
+		  if (bit_str_len <= MAXBITS) {
             gtk_widget_set_sensitive(X->bit_panel, TRUE);
-
+			
             STRCPY(label, " 0");
             for (i = 0; i < MAXBITS; i++) {
-                label[1] = (i < bit_str_len) ? bit_str[bit_str_len-i-1] : '0';
-                gtk_label_set_text(GTK_LABEL(X->bits[MAXBITS - i - 1]), label);
+			  label[1] = (i < bit_str_len) ? bit_str[bit_str_len-i-1] : '0';
+			  gtk_label_set_text(GTK_LABEL(X->bits[MAXBITS - i - 1]), label);
             }
-
+			
             return;
-        }
-    }
-    gtk_widget_set_sensitive(X->bit_panel, FALSE);
+		  }
+		}
+		gtk_widget_set_sensitive(X->bit_panel, FALSE);
+		
+	  }
+	  break;
+	case exprs:
+	  {
+		int MP[MP_SIZE];
+		int bit_str_len, i;
+		char *bit_str, label[3], tmp[MAXLINE];
+		int ret = usable_num(MP);
+
+		if (ret || !is_integer(MP)) {
+		  gtk_widget_set_sensitive(X->bit_panel, FALSE);
+		  return;
+		}
+		
+		bit_str = make_fixed(MP, tmp, BIN, MAXLINE, FALSE);
+		bit_str_len = strlen(bit_str);
+		if (bit_str_len <= MAXBITS) {
+		  gtk_widget_set_sensitive(X->bit_panel, TRUE);
+		  
+		  STRCPY(label, " 0");
+		  for (i = 0; i < MAXBITS; i++) {
+			label[1] = (i < bit_str_len) ? bit_str[bit_str_len-i-1] : '0';
+			gtk_label_set_text(GTK_LABEL(X->bits[MAXBITS - i - 1]), label);
+		  }
+		}
+	  }
+	  break;
+	}
 }
 
 
@@ -3265,7 +3308,7 @@
             gtk_widget_show(X->adv_panel);
             gtk_widget_hide(X->fin_panel);
             gtk_widget_show_all(X->mode_panel);
-            if (v->syntax == npa) {
+			if (v->bitcalculating_mode) {
                 gtk_widget_show_all(X->bit_panel);
             } else {
                 gtk_widget_hide(X->bit_panel);
@@ -3359,6 +3402,14 @@
     gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), state);
 }
 
+static void
+set_show_bitcalculating_toggle(int state)
+{
+    GtkWidget *mi;
+
+    mi = gtk_ui_manager_get_widget(X->ui, "/MenuBar/ViewMenu/Bitcalculating");
+    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), state);
+}
 
 static void
 set_show_zeroes_toggle(int state)
