Bug 000319

When Created: 05/04/2000 22:00:52
Against DJGPP version: 2.03
By whom:
Abstract: error handling hexadecimal data
i think this is a djgpp problem . . . sorry if not.

when compiled in djgpp, the c++program below fails to handle
hexadecimals properly.


// bitwise: do bitwise operations with hex numbers

#include <stdio.h>
#include <iostream.h>

int main(int nArgs, char* pszArgs[])
  // set format to hex

  // input first
  cout << "Enter first argument as a four-digit hex: ";
  int nFirst;
  cin >> nFirst;

  // input second
  cout << "Enter second argument: ";
  int nSecond;
  cin >> nSecond;

    // calculate & output results
  cout << "\n";
  cout << "argument1 & argument2 = 0x"
       << (nFirst & nSecond) << "\n";
  cout << "argument1 | argument2 = 0x"
       << (nFirst | nSecond) << "\n";
  cout << "argument1 ^ argument2 = 0x"
       << (nFirst ^ nSecond) << "\n";

  // end program
  return 0;



the first argument is entered, but instead of collecting the second
argument from the user, the program assumes a value of zero and
contunues with the final output, as below.


Enter first argument as a four-digit hex: 0x1234
Enter second argument:
argument1 & argument2 = 0x0
argument1 | argument2 = 0x0
argument1 ^ argument2 = 0x0


any guidance toward working around this problem will be much appreciated.

Note added: 05/04/2000 22:00:34
By whom:
incorrect email address in original submission, it's

Note added: 05/18/2000 07:00:02
By whom:
Try following:

#include <iostream>
#include <string>

int main (void)
   int First;
   string tmp;
   cin >> First;
   cin >> tmp;
   cout << tmp;
   return 0;  

And enter 0x1234 at prompt. You'll see x1234 as value of tmp. So
'cin >> First;' stops reading when encounters 'x'. (However I tested this
under Linux only and got similar results from the first example above)

Note added: 05/20/2000 12:10:57
By whom:
According to similar testing made by Salvador Eduardo Tropea, the test
program behaves the same on Linux and on DOS.  So this is not a bug,
certainly not a DJGPP bug.  The hex read operation does not grok the
"0x" prefix, that's all.

I'm closing this bug report.

Closed on 05/20/2000 12:12:32: Usage error, not a bug.
By whom:

  webmaster     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010