Re: Is this acceptable (i.e., compliant) code?
From: anonymous (iunknown2k4_at_yahoo.co.in)
Date: 08/11/04
- Next message: RJJ: "Two Questions"
- Previous message: Eric Sosman: "Re: global variable name conflict with standard header"
- In reply to: Mark F. Haigh: "Re: Is this acceptable (i.e., compliant) code?"
- Next in thread: CBFalconer: "Re: Is this acceptable (i.e., compliant) code?"
- Reply: CBFalconer: "Re: Is this acceptable (i.e., compliant) code?"
- Reply: pete: "Re: Is this acceptable (i.e., compliant) code?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Aug 2004 09:55:35 -0700
> #include <stdio.h>
> #include <stddef.h>
> #include <limits.h>
> static void printbits(void *mem, size_t size)
> {
> size_t i;
> unsigned char mask;
> char *p = mem;
>
> for(i = 0; i < size; i++) {
> for(mask = 1 << (CHAR_BIT - 1); mask; mask >>= 1)
> putc((mask & p[i]) ? '1' : '0', stdout);
>
> putc(' ', stdout);
> }
> putc('\n', stdout);
> }
The function above prints from LSB..MSB, I wanted to print in the reverse order
I tried using
for(i = size; i >= 0 ; i--)
But goes into an infinite loop because of unsigned int comparison, so I used
for(i = size; i != UINT_MAX; i--)
This works but is there a better way to do that?
- Next message: RJJ: "Two Questions"
- Previous message: Eric Sosman: "Re: global variable name conflict with standard header"
- In reply to: Mark F. Haigh: "Re: Is this acceptable (i.e., compliant) code?"
- Next in thread: CBFalconer: "Re: Is this acceptable (i.e., compliant) code?"
- Reply: CBFalconer: "Re: Is this acceptable (i.e., compliant) code?"
- Reply: pete: "Re: Is this acceptable (i.e., compliant) code?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]