[ create a new paste ] login | about

Link: http://codepad.org/rTLYLwES    [ raw code | output | fork ]

slevy1ster - C, pasted on Jul 17:
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int main()
{
    static char digits[] = "0123456789abcdef";
    char buf[(sizeof(unsigned long) << 3) + 1];
    char *ptr, *end;
    int base;
    unsigned long value;

    base = 16;
    value = -LONG_MAX -1;
    end = ptr = buf + sizeof(buf) - 1;
    *ptr = '\0';
    
    printf("Start with: %ld and size of buffer is %d \(size of usi long is %d\) \n",value, (sizeof(unsigned long) << 3) + 1,sizeof(unsigned long));
    do {
        *--ptr = digits[value % base];
        value /= base;
        printf("Processing: %ld and ptr is %s\n",value,ptr);
    } while (ptr > buf && value);

    puts(ptr);

return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
Start with: -2147483648 and size of buffer is 33 (size of usi long is 4) 
Processing: 134217728 and ptr is 0
Processing: 8388608 and ptr is 00
Processing: 524288 and ptr is 000
Processing: 32768 and ptr is 0000
Processing: 2048 and ptr is 00000
Processing: 128 and ptr is 000000
Processing: 8 and ptr is 0000000
Processing: 0 and ptr is 80000000
80000000


Create a new paste based on this one


Comments: