Printhex in gcc

Gast #4834428
Lesenswert?

Ich will eine zahl gröesser 2^32 in gnu cc in Hexformat ausgeben.

unsigned long long int val = 4 295 000 000;
val ist dann wohl unsigned long long int? also bis 64 bit.

printf ("%o2x",val);

Gibt: Typen passen nicht.

Bei unsigned int val = 2561;

geht printf ("%o2x",val); (hex a01)
M.
Gast #4834436
Lesenswert?

Hallo Matthias,

ich kann aus deinem Beitrag leider nicht genau erkennen was du meinst.
Folgendes compiliert bei mir ohne Warnung oder sonstiges:
1
   unsigned long long int val = 4295000000;
2
   printf ("%llx",val);
Persönliche Seite #4834485
Lesenswert?

matthias schrieb:
> Ich will eine zahl gröesser 2^32 in gnu cc in Hexformat ausgeben.
>
> unsigned long long int val = 4 295 000 000;
> val ist dann wohl unsigned long long int? also bis 64 bit.

Ja, es ist größer als 2^32-1 = 4 294 967 295.

Ob es long long sein muss, hängt von der ABI ab.  Auf LP64 genügt long, 
auf ILP64 genügt int um einen 64-BIt Wert darzustellen.

> printf ("%o2x",val);

Um einen unsigned long long als hex auszugeben:
  
1
#include <stdio.h>
2

3
int main ()
4
{
5
    printf ("%llx", -1ull);
6
}
 
um einen unsigned 64-Bit Wert als hex auszugeben:
 
1
#include <stdio.h>
2
#include <inttypes.h>
3

4
int main ()
5
{
6
    printf ("%" PRIx64, UINT64_C (-1));
7
}
 
Beides erfordert mindestens C99.
Gast #4834577
Lesenswert?

ja danke auf llx wär ichnicht gekommen
so was wie "lllx" für __int128 Typen musste ich mir selber schreiben 
also ein printf_128 in dezimal.
Thx

//        \\\//
//        (o|o)
// --o00o-------oOOo--------------------
// printf_128
// -------------------------------------

void printf_128(__int128 path)
{

// Ausgabe int128 im Dezimalformat
// jeweils 6 Ziffern durch Kommata getrennt

int ziffer[42];
int cnt = 0;
int loop;
if (path ==0) printf ("0");
while (path>0)
        {
        ziffer[cnt]=path%10;
        path=path/10;
        cnt++;
        }

for (loop = cnt-1;loop>=0;loop--)
        {
        printf("%i",ziffer[loop]);
        if ( (loop%6==0) && (loop>0) )
                printf(",");
        }
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren