www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/03/11:03:31

Date: Wed, 3 Feb 1999 16:59:50 +0100
From: anarko <anarko AT flashback DOT net>
X-Mailer: The Bat! (v1.19) S/N 9FA473A9
X-Priority: 3 (Normal)
Message-ID: <15708.990203@flashback.net>
To: djgpp AT delorie DOT com
Subject: what is wrong with this?
References: <Pine DOT LNX DOT 3 DOT 91 DOT 990201164419 DOT 5366B-100000 AT aditya DOT unigoa DOT ernet DOT in>
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

Hello everybody, i have a little problem,
i wrote a little routine that resets a specific
bit in a char, and it worked fine. then i just wanted
to reduce the lines of code it was written in
to one line or something and it doesnt work correct,

i reduced it to:
bittmp = tmp << 2;
bittmp = ((tmp >> 7) << 7) | (bittmp >> 2);

without problems, but when i wrote it to:
bittmp = ((tmp >> 7) << 7) | ((tmp << 2) >> 2);

it did no longer work (it returned 11111111 binary, as i inputted in
it)

the code is below if someone wants to take a peek at it:


#include <stdio.h>
#include <stdlib.h>

void ToBin8(unsigned char numb);

int main ()
{
        unsigned char  tmp;
        unsigned char  bittmp;

        tmp=0xFF;            //11111111 in binary
        ToBin8(tmp);
        printf("\n");
        //reset bit 6
        bittmp = tmp << 2;
        bittmp = ((tmp >> 7) << 7) | (bittmp >> 2);
//        bittmp = ((tmp >> 7) << 7) | ((tmp << 2) >> 2);   //this
line isnt working

        ToBin8(bittmp);
        printf("\n");
        return 0;
}

void ToBin8(unsigned char numb)
{
        unsigned char cnt,a;
        int tmp;
        cnt = 128;
        for(a=0; a<8;a++)
        {
                tmp = numb - cnt;
                if (tmp >= 0)
                {
                        printf("1");
                        numb = tmp;
                }
                else printf("0");
                cnt = cnt / 2;
        }
} /* ToBin8(uchar numb) */


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019