Article View: es.comp.os.linux.programacion
Article #9512Re: Como acceder al bit x de un dato
From: Santiago Intxausti
Date: Tue, 18 Jun 2002 21:52
Date: Tue, 18 Jun 2002 21:52
42 lines
1733 bytes
1733 bytes
Angel wrote: > Suponiendo q tenemos un dato de n bytes, com podria acceder al bit x?? > en C o C++. > > ej: > > bool cual_es_el_valor_del_bit(n_bit); > > Muy facil, el metodo se llama enmascaramiento. Se hace de la siguiente manera: [valor_bit] = [byte] & [mascara]; Mascara bit N�0 = 1(decimal) bit N�1 = 2 bit N�2 = 4 bit N�3 = 8 bit N�4 = 16 bit n�5 = 32 bit n�6 = 64 bit n�7 = 128 Ejemplo: Si quieres sacar el valor del bit n�4 para guardarlo en la variable "bit" de la variable "byte" seria de la siguiente manera. bit = byte & 16
Technical Details
Message-ID:
<aeoa4e$kbb$1@news.ya.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!news.telia-iberia.com!news.rediris.es!news.ya.com!yacom!not-for-mailReferences:
<aekvlb$81hpu$1@ID-148170.news.dfncis.de>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,8245fc4b08721416 X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2002-06-18 14:54:13 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!news.telia-iberia.com!news.rediris.es!news.ya.com!yacom!not-for-mail From: Santiago Intxausti <intxausti@intxausti.net> Newsgroups: es.comp.os.linux.programacion Subject: Re: Como acceder al bit x de un dato Date: Tue, 18 Jun 2002 23:52:57 +0200 Organization: ya.com internet factory Lines: 42 Message-ID: <aeoa4e$kbb$1@news.ya.com> References: <aekvlb$81hpu$1@ID-148170.news.dfncis.de> Reply-To: intxausti@intxausti.net NNTP-Posting-Host: 80-33-247-76.adsl.ya.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8Bit X-Trace: news.ya.com 1024437198 20843 80.33.247.76 (18 Jun 2002 21:53:18 GMT) X-Complaints-To: newsmaster@ya.com NNTP-Posting-Date: Tue, 18 Jun 2002 21:53:18 +0000 (UTC) User-Agent: KNode/0.7.1