🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #10748

Re: Inversion de bits

#10748
From: Ripe/7a69
Date: Thu, 07 Feb 2002 16:11
37 lines
1602 bytes
Jordi Canton wrote:

> Alguien conoce alguna manera elegante y eficiente de invertir el orden
> de todos los bits de un byte en C?
> 
> es decir tengo un byte con los bits as�
> 
> b0 b1 b2 b3 b4 b5 b6 b7
> 
> y quiero obtener un byte con los bits de esta otra forma:
> 
> b7 b6 b5 b4 b3 b2 b1 b0
> 
> 
> Jordi
> 
> 
> 
> 

Se me ocurren varias maneras.... suponiendo que queremos invertir...

	unsigned char a;

Puedes hacer

	a=-a-1;
o

	a=-(a-255);

Se puede aplicar lo mismo a otros tipos de datos.


PD: Este metodo depende del tipo de numeros negativos que se este usando 
,(ahora no recuedo el nombre) pero se suele usar uno con el que esto 
funciona.
Technical Details
Message-ID: <3C62A71F.80109@NO-SPAM-HERE7a69ezine.org>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!newsfeed.bcn.ttd.net!news.bcn.ttd.net!not-for-mail
References: <3C61171A.5F9E4911@eq.upc.es>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,bd33173853cfd14f
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2002-02-09 16:42:38 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!newsfeed.bcn.ttd.net!news.bcn.ttd.net!not-for-mail
From: Ripe/7a69 <ripe@NO-SPAM-HERE7a69ezine.org>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Inversion de bits
Date: Thu, 07 Feb 2002 17:11:11 +0100
Organization: Telefonica Transmision de Datos
Lines: 38
Message-ID: <3C62A71F.80109@NO-SPAM-HERE7a69ezine.org>
References: <3C61171A.5F9E4911@eq.upc.es>
NNTP-Posting-Host: 80-24-12-216.uc.nombres.ttd.es
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20020203