🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.comp.lang.csharp
Article #9597

Re: operacje na bitach

#9597
From: Hilarion
Date: Tue, 25 Oct 2005 18:59
39 lines
1795 bytes
> implementacja powyzszego zajmuje 9 bajtow ichnego kodu:
>
> public static byte foo(int x)
> {
>    return (byte)(x ^ 0xff);
> /*
>        IL_0000:  ldarg.0
>        IL_0001:  ldc.i4 255
>        IL_0006:  xor
>        IL_0007:  conv.u1
>        IL_0008:  ret
> */
> }
>
> ale w sumie mozna to zrobic szybciej i latwiej (tylko 4 bajty kodu).
>
> public static byte bar(int x)
> {
>    return (byte)(~x);
> /*
>        IL_0000:  ldarg.0
>        IL_0001:  not
>        IL_0002:  conv.u1
>        IL_0003:  ret
> */
> }


A co wychodzi z poniższego?

public static byte bar(int x)
{
   return ~((byte)x);
}

No i co z wydajnością? Czy operacja negacji jest szybsza na "int" niż
na "byte"? Pewnie nie (jedna operacja procesora).

Hilarion 
Technical Details
Message-ID: <djlv6s$sq0$1@news.onet.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mail
References: <djkvmh$ugp$1@news.onet.pl> <djl2uc$bp5$1@atlantis.news.tpi.pl> <djl7bg$u30$1@news.onet.pl> <djl898$2pu$1@news.onet.pl> <djlgum$pf0$1@achot.icm.edu.pl> <djli8q$qrs$1@achot.icm.edu.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.gazeta.pl!news.onet.pl!not-for-mail
From: "Hilarion" <hilarion@SPAM.op.SMIECI.pl>
Newsgroups: alt.pl.comp.lang.csharp
Subject: Re: operacje na bitach
Date: Tue, 25 Oct 2005 20:59:10 +0200
Organization: Onet.pl
Lines: 40
Message-ID: <djlv6s$sq0$1@news.onet.pl>
References: <djkvmh$ugp$1@news.onet.pl> <djl2uc$bp5$1@atlantis.news.tpi.pl> <djl7bg$u30$1@news.onet.pl> <djl898$2pu$1@news.onet.pl> <djlgum$pf0$1@achot.icm.edu.pl> <djli8q$qrs$1@achot.icm.edu.pl>
NNTP-Posting-Host: fw.elfin.pl
Mime-Version: 1.0
X-Trace: news.onet.pl 1130266652 29504 213.25.37.46 (25 Oct 2005 18:57:32 GMT)
X-Complaints-To: usenet@news.onet.pl
NNTP-Posting-Date: Tue, 25 Oct 2005 18:57:32 +0000 (UTC)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-Sender: 9KSiimrLScNqWiVTMiVMJQ==
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-Priority: 3
X-MSMail-Priority: Normal
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit