🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: operacje na bitach

#9600
From: Ulvhedin
Date: Tue, 25 Oct 2005 13:37
50 lines
1872 bytes
Karol napisał(a):
> Witam
> 
> I znowu ja. Mam jakąś liczbę typu int. Muszę zanegować jej bity i pobrać
>     tylko jeden bajt z wyniku (najmniej znaczÄ…cy) jak to elegancko
> zrobić w c#. Oczywiście .net 1.1 .



a moze tak:
(przyklad dotyczy np odczytania statusu pliku a opisuje to jakas liczba,
kiedys tam bawilem sie jakims plikiem dziekiej bazy i trzeba bylo
odczytac wlasnie staus pliku ktory byl zapisany w postaci liczby int chyba

[FlagsAttribute]
public enum FileStatus: byte
{
	stan1			= 1,
	stan2			= 2,
	stan3			= 4,
	stan4			= 8,
	stan5			= 16,
	stan6			= 32,
	stan7			= 64,
	stan8			= 128			
}

a pozniej np.

private  bool GetFileStatus(int liczba, FileStatus filestatus)
{
	bool s = ((liczba & ((byte)filestatus))!=0);
	return s;
}
a uzywalem tak:
// _alldata jest typu byte

if( GetFileStatus(BitConverter.ToInt16(_alldata,2), FileStatus.stan1) )
{

	// to jakis tam stan np. Locked i cos tam z tym robilem
}



czysto ladnie i przejrzyscie.. ;)

Pozdrawiam

Jarek
Technical Details
Message-ID: <djlcf5$2i9t$1@node3.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.atman.pl!not-for-mail
References: <djkvmh$ugp$1@news.onet.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.atman.pl!not-for-mail
From: Ulvhedin <jtWYTNIJ@ronwe.com>
Newsgroups: alt.pl.comp.lang.csharp
Subject: Re: operacje na bitach
Date: Tue, 25 Oct 2005 15:37:18 +0200
Organization: ATMAN
Lines: 52
Message-ID: <djlcf5$2i9t$1@node3.news.atman.pl>
References: <djkvmh$ugp$1@news.onet.pl>
Reply-To: jtWYTNIJTO@ronwe.com
NNTP-Posting-Host: luigi.toya.net.pl
Mime-Version: 1.0
X-Trace: node3.news.atman.pl 1130247461 84285 217.113.231.221 (25 Oct 2005 13:37:41 GMT)
X-Complaints-To: abuse@atman.pl
NNTP-Posting-Date: Tue, 25 Oct 2005 13:37:41 +0000 (UTC)
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: pl, en-us, en
In-Reply-To: <djkvmh$ugp$1@news.onet.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit