Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2004, 02:47 AM
Registered User
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use of long long int

Hi,
I'm pretty new to C coding, and I'm trying to use long long (64-bit) integers. I ran the following test program on z/OS (under USS), and on Windows 2000, but I don't understand the results:
Does anyone have an idea why the HEX print only prints the content of the first 4 bytes? Or why on Windows, the DECIMAL print produces a negative?
I think I understand the result of the BYTE print, with Windows being a little Endian, and so the entire value is stored in reverse byte order..

Test program:

#include <stdio.h>
#include <stdlib.h>
void main(void)
{
   unsigned long long juul = 123456789012345678LL;
   unsigned char *pjuul;
   int i;

   printf("juuld: %lld\n",juul);
   printf("juulx: %016X\n",juul);
   pjuul = (char *) &juul;
   printf("juulb: ");
   for (i = 0;i < 8; i++) printf("%02X",*(pjuul + i));
   printf("\n");
   system("PAUSE");
   exit (0);
}
/* PRODUCES on z/OS: on Windows:
    juuld: 123456789012345678 -1506741426
    juulx: 0000000001B69B4B 00000000A630F34E
    juulb: 01B69B4BA630F34E 4EF330A64B9BB601
   AND ACCORDING TO THE CALCULATOR, THIS LAST ONE IS CORRECT
*/


Thanks beforehand,



Juul
 
Old November 30th, 2005, 04:16 PM
tnd tnd is offline
Authorized User
 
Join Date: Jun 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe its because microsoft C doesn't understand your format codes.
try using
printf("%.I64", juul);
printf("%16.I64X", juul);

Althought I haven't checked but I think signed 32 bit BCD representation of A630F34E is -1506741426

 
Old September 20th, 2006, 06:07 PM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You stored an int type and read it as a decimal: the highest order bit in any decimal number is either 0 for positive numbers, or 1 for negative numbers. Assuming your int value was large enough to change the value of the highest order bit to a 1, reading as it as a decimal number interpreted it to be a negative number.

Paul1307





Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the difference between an int and a long jnrico C++ Programming 4 March 4th, 2007 01:29 AM
Long Long int to bin walid C# 0 January 23rd, 2007 12:47 PM
Double in Long int walid C# 0 January 20th, 2007 08:50 AM
Use of long long int jvanp C++ Programming 7 October 3rd, 2004 01:59 PM
Modifying long text in a long field sajsal Classic ASP Databases 1 February 20th, 2004 12:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.