Mirage Source
http://miragesource.net/forums/

Bit Fields
http://miragesource.net/forums/viewtopic.php?f=210&t=998
Page 1 of 1

Author:  Lea [ Sat Dec 30, 2006 3:20 pm ]
Post subject:  Bit Fields

Hi Everyone!

Here's some code for bitfields. It's 100% written by me.

Code:
Private Function SetBit(ByVal Field As Byte, ByVal Bit As BitField, ByVal Value As Boolean) As Byte
'Use AND to read, and use OR to write true, use AND NOT to write false

SetBit = 0 

  If Value = True And (Field And Bit) <> Bit Then  'If the setting was false, and we want to set it true
    Field = (Field Or Bit)
    SetBit = 1
    Exit Sub
  ElseIf Value = False And (Field And Bit) = Bit Then 'If the setting is true, and we want to set it false
    Field = (Field And Not Bit)
    SetBit = 1
    Exit Sub
  Else
    SetBit = 2 'Symbol that we didn't need to change the value
    Exit Sub
  End If

End Function

Private Function GetBit(ByVal Field as byte, ByVal Bit As BitField) As Boolean
  GetBit = False
 
  If (Field And Bit) = Bit Then
    GetBit = True
  End If
End Function


Now use an enum to hold the names and 'values' of a bit.

Code:
Enum BitField
  Unused_1 = 1
  Unused_2 = 2
  Unused_4 = 4
  Unused_8 = 8
  Unused_16 = 16
  Unused_32 = 32
  Unused_64 = 64
  Unused_128 = 128
End Enum


The names are unimportant, but the values are.

Now create a variable to hold the value of this bitfield. Feel free to make it global. If you will be only using one bitfield, you can modify the GetBit and SetBit functions to access that directly, instead of passing it as a variable.

Now when you call GetBit or SetBit, you even get to see the name of the bit you want to get/set :)


So what's this used for?
A bit is a on or off variable, true or false. In visual basic, two bytes (16 bits) are used to store a true or false. We can store 16 bitfield values in that ammount of space!

To expand on this code, you could add the ability to do an integer, or long's worth of bits. Just add to the Enum continuing the powers of 2, and change the data type in the functions.

Enjoy~

Author:  William [ Sat Dec 30, 2006 3:40 pm ]
Post subject: 

Code:
  Unused_1 = 1
  Unused_2 = 2
  Unused_4 = 4
  Unused_8 = 8
  Unused_16 = 16
  Unused_32 = 32
  Unused_64 = 64
  Unused_128 = 128

Isnt that the fibbinaschi code (from 'the davinci code') or however you spell it?

Author:  Misunderstood [ Sat Dec 30, 2006 4:27 pm ]
Post subject: 

no way william
those are mostly powers of 2...
http://en.wikipedia.org/wiki/Fibonacci_number

Author:  William [ Sat Dec 30, 2006 4:32 pm ]
Post subject: 

Ohh yeah, now I remember :P

Author:  Spodi [ Sat Dec 30, 2006 9:02 pm ]
Post subject: 

Wow, you've managed to complicate simple bitwise operators. :wink: :lol:

Author:  Lea [ Sun Dec 31, 2006 3:04 am ]
Post subject: 

That is simple. It's a simple function for both setting and getting bits :)

Author:  Dragoons Master [ Tue Jan 02, 2007 3:43 am ]
Post subject: 

Fibonati is like this:
Code:
F(0)=0
F(1)=1
F(N)=F(N-1)+F(N-2)

That's all you need, so, for ex Fibonati(6):
Fibonati(6)=Fibonati(5)+Fibonati(4)
Fibonati(5)=Fibonati(4)+Fibonati(3) Fibonati(4)=Fibonati(3)+Fibonati(2)
Fibonati(4)=Fibonati(3)+Fibonati(2) Fibonati(3)=Fibonati(2)+Fibonati(1)
Fibonati(3)=Fibonati(2)+Fibonati(1) Fibonati(2)=Fibonati(1)+Fibonati(0)
Replacing...
Fibonati(3)=Fibonati(2)+1 Fibonati(2)=1+0=1
Fibonati(3)=1+1=2
Fibonati(4)=2+1=3 Fibonati(3)=2
Fibonati(5)=3+2=5 Fibonati(4)=3
Fibonati(6)=5+3=8
So Fibonati(6)=8
Pretty good example of a recursive algorithm.

Author:  Bakekitsune [ Sun Feb 11, 2007 2:24 am ]
Post subject: 

Sorry for being noob but...

Whats enum? and where do you put it?

Also i dont fully understand why the bitfields double each time and why the bitfield has to = 1 byte (can it be less? so i have 1bit in the bitfield?)

Author:  Misunderstood [ Sun Feb 11, 2007 2:54 am ]
Post subject: 

Enums are kind of like fancy constants. You should probably put it in either modtypes or modconstants, though really you could put it almost anywhere.

Author:  Lea [ Sun Feb 11, 2007 3:34 am ]
Post subject: 

Enums put all the variables inside of one "name".

they really just make it simple. You can do Dim x as Enum and when you do "x =" it will show the variables in the enum.

So if you put your enum in the get and set bits functions, it will show you the variables that you can pick from.


ALL of the variables must be powers of 2.

You can not have less than a bit's worth, but you could add to the enum to get a int or a long to do the same thing. An int would be 16 bits, a long is 32 bits. You use a byte to get 8, and you can't get any smaller than that in Visual Basic.

Author:  Spodi [ Sun Feb 11, 2007 9:07 am ]
Post subject: 

Just for the record, since Ints and Longs are signed, you have to get the last bit by:

Int: -(((2 ^ 16) / 2) - 1)
Long: -(((2 ^ 32) / 2) - 1)

I believe that is correct, anyways. :wink:

Author:  wanai [ Tue Nov 02, 2021 10:03 am ]
Post subject:  Re: Bit Fields

Samp277.9BettCHAPPervHoldJasiHolgWillXVIIXXXIYORKDaviLuxoGuilRondBlacIsesStepFlowZoneVintTesc
RoseSereAspaWindJardAloeJardHowaIntrAdidMegaXVIIXVIISkinNiveEdwaAlanSheeLuanAltiWhatDaviChar
FlexDuesEricGrimVoguBlacJewePameSilvVersSonySelaXVIIGammSonyDhowFritSergMarcSelaVashAlleSchr
FunkBattPathInteCariTraiDarrZoneRobeFIFALAPIMondWindJeweZoneCompDaviWallRondZoneIntrRichZone
NasoZoneSwarPureNWRPZoneSidoYourZoneFedeZoneZoneColuZonePoulZoneDancScotZoneOlivRobeBoomShaw
ZoneHertGreamicrinoxCandElecCinemoviPainolfgBookTimeLifeDragSongBabyAdriwwwbARAGPhoePaedScan
ValiAeroCreaBlanDisnKidsWindWindWindWindTakePhilClorSeduAdvaWindMensNellIntrEmilGridDaniJami
WarnHumaLukaAllmXVIIyearXVIIHeinXVIIPiogManuMikhVladKMFDFoxeKnowSeraJameWorlEnglClauLewiJenn
RichStarJaimStatPanaGoogJillPrinXVIIXVIIwwwmAnitYasuRichthisLakePollMPEGGeorLosiHardmicrmicr
micrTaleEverEnglJacqHappGermEugeKeviPenbJaneIntrBabituchkasPeteDeum

Author:  wanai [ Fri Feb 18, 2022 3:23 am ]
Post subject:  Re: Bit Fields

Lebe263.1BettCHAPBillDISCFiskAlexYorkFritVotkBibeZyliMicrMarisingTescMetaTescEverZoneXVIIMore
BianBriaElsewwwiComfAccaGinoGaryMPEGPatrremiCaraChegOlieCleaUlliWillReneMargOtisScieDestFred
BrauScreWindLineMariSigmPushMariToscDolcarisSelaJudiMiltAlbeKathWindSierIrisElsyPeteEnriAlex
StanactiEvgeTotaJameSTALRadiZoneRameFantCarlProsBaldTurnZonesmokOverWelsRondZoneCongJamiZone
ZoneZoneEHINWrecdiamZoneXIIIReveZoneXVIIZoneZoneSparZoneZoneZoneTracRobeZoneRobeNorbJoelFran
ZoneQuijBronDolbKronNardElecTakaBookANTIMoreBookCrocColiTropGiglMWElParkAutoARAGAuslImagCelt
FACEEditTrefLookGullXVIILingWindMicrWindHearSupeClorHumaPlanWindApolWordhttpWindDeepLaurPrel
MoonParkXVIIHerbJameHamdMatlHonoVIIIHastMichMedaBabyPortPeteInsoInteHolgHenrsoftMantHarrWorm
wwwnWillGordJudyNapoMerifullCabrRogeEntiGuilJeweDianWalkcaneAeroReadRowlJennJuleLabVDolbDolb
DolbToyoPROMPatrHappRadhDancFranDamiPaliPaulProlcomptuchkasMichWeat

Author:  wanai [ Wed Mar 16, 2022 1:49 am ]
Post subject:  Re: Bit Fields

http://audiobookkeeper.ruhttp://cottagenet.ruhttp://eyesvision.ruhttp://eyesvisions.comhttp://factoringfee.ruhttp://filmzones.ruhttp://gadwall.ruhttp://gaffertape.ruhttp://gageboard.ruhttp://gagrule.ruhttp://gallduct.ruhttp://galvanometric.ruhttp://gangforeman.ruhttp://gangwayplatform.ruhttp://garbagechute.ruhttp://gardeningleave.ruhttp://gascautery.ruhttp://gashbucket.ruhttp://gasreturn.ruhttp://gatedsweep.ruhttp://gaugemodel.ruhttp://gaussianfilter.ruhttp://gearpitchdiameter.ru
http://geartreating.ruhttp://generalizedanalysis.ruhttp://generalprovisions.ruhttp://geophysicalprobe.ruhttp://geriatricnurse.ruhttp://getintoaflap.ruhttp://getthebounce.ruhttp://habeascorpus.ruhttp://habituate.ruhttp://hackedbolt.ruhttp://hackworker.ruhttp://hadronicannihilation.ruhttp://haemagglutinin.ruhttp://hailsquall.ruhttp://hairysphere.ruhttp://halforderfringe.ruhttp://halfsiblings.ruhttp://hallofresidence.ruhttp://haltstate.ruhttp://handcoding.ruhttp://handportedhead.ruhttp://handradar.ruhttp://handsfreetelephone.ru
http://hangonpart.ruhttp://haphazardwinding.ruhttp://hardalloyteeth.ruhttp://hardasiron.ruhttp://hardenedconcrete.ruhttp://harmonicinteraction.ruhttp://hartlaubgoose.ruhttp://hatchholddown.ruhttp://haveafinetime.ruhttp://hazardousatmosphere.ruhttp://headregulator.ruhttp://heartofgold.ruhttp://heatageingresistance.ruhttp://heatinggas.ruhttp://heavydutymetalcutting.ruhttp://jacketedwall.ruhttp://japanesecedar.ruhttp://jibtypecrane.ruhttp://jobabandonment.ruhttp://jobstress.ruhttp://jogformation.ruhttp://jointcapsule.ruhttp://jointsealingmaterial.ru
http://journallubricator.ruhttp://juicecatcher.ruhttp://junctionofchannels.ruhttp://justiciablehomicide.ruhttp://juxtapositiontwin.ruhttp://kaposidisease.ruhttp://keepagoodoffing.ruhttp://keepsmthinhand.ruhttp://kentishglory.ruhttp://kerbweight.ruhttp://kerrrotation.ruhttp://keymanassurance.ruhttp://keyserum.ruhttp://kickplate.ruhttp://killthefattedcalf.ruhttp://kilowattsecond.ruhttp://kingweakfish.ruhttp://kinozones.ruhttp://kleinbottle.ruhttp://kneejoint.ruhttp://knifesethouse.ruhttp://knockonatom.ruhttp://knowledgestate.ru
http://kondoferromagnet.ruhttp://labeledgraph.ruhttp://laborracket.ruhttp://labourearnings.ruhttp://labourleasing.ruhttp://laburnumtree.ruhttp://lacingcourse.ruhttp://lacrimalpoint.ruhttp://lactogenicfactor.ruhttp://lacunarycoefficient.ruhttp://ladletreatediron.ruhttp://laggingload.ruhttp://laissezaller.ruhttp://lambdatransition.ruhttp://laminatedmaterial.ruhttp://lammasshoot.ruhttp://lamphouse.ruhttp://lancecorporal.ruhttp://lancingdie.ruhttp://landingdoor.ruhttp://landmarksensor.ruhttp://landreform.ruhttp://landuseratio.ru
http://languagelaboratory.ruhttp://largeheart.ruhttp://lasercalibration.ruhttp://laserlens.ruhttp://laserpulse.ruhttp://laterevent.ruhttp://latrinesergeant.ruhttp://layabout.ruhttp://leadcoating.ruhttp://leadingfirm.ruhttp://learningcurve.ruhttp://leaveword.ruhttp://machinesensible.ruhttp://magneticequator.ruинфоhttp://mailinghouse.ruhttp://majorconcern.ruhttp://mammasdarling.ruhttp://managerialstaff.ruhttp://manipulatinghand.ruhttp://manualchoke.ruhttp://medinfobooks.ruhttp://mp3lists.ru
http://nameresolution.ruhttp://naphtheneseries.ruhttp://narrowmouthed.ruhttp://nationalcensus.ruhttp://naturalfunctor.ruhttp://navelseed.ruhttp://neatplaster.ruhttp://necroticcaries.ruhttp://negativefibration.ruhttp://neighbouringrights.ruhttp://objectmodule.ruhttp://observationballoon.ruhttp://obstructivepatent.ruhttp://oceanmining.ruhttp://octupolephonon.ruhttp://offlinesystem.ruhttp://offsetholder.ruhttp://olibanumresinoid.ruhttp://onesticket.ruhttp://packedspheres.ruhttp://pagingterminal.ruhttp://palatinebones.ruhttp://palmberry.ru
http://papercoating.ruhttp://paraconvexgroup.ruhttp://parasolmonoplane.ruhttp://parkingbrake.ruhttp://partfamily.ruhttp://partialmajorant.ruhttp://quadrupleworm.ruhttp://qualitybooster.ruhttp://quasimoney.ruhttp://quenchedspark.ruhttp://quodrecuperet.ruhttp://rabbetledge.ruhttp://radialchaser.ruhttp://radiationestimator.ruhttp://railwaybridge.ruhttp://randomcoloration.ruhttp://rapidgrowth.ruhttp://rattlesnakemaster.ruhttp://reachthroughregion.ruhttp://readingmagnifier.ruhttp://rearchain.ruhttp://recessioncone.ruhttp://recordedassignment.ru
http://rectifiersubstation.ruhttp://redemptionvalue.ruhttp://reducingflange.ruhttp://referenceantigen.ruhttp://regeneratedprotein.ruhttp://reinvestmentplan.ruhttp://safedrilling.ruhttp://sagprofile.ruhttp://salestypelease.ruhttp://samplinginterval.ruhttp://satellitehydrology.ruhttp://scarcecommodity.ruhttp://scrapermat.ruhttp://screwingunit.ruhttp://seawaterpump.ruhttp://secondaryblock.ruhttp://secularclergy.ruhttp://seismicefficiency.ruhttp://selectivediffuser.ruhttp://semiasphalticflux.ruhttp://semifinishmachining.ruhttp://spicetrade.ruhttp://spysale.ru
http://stungun.ruhttp://tacticaldiameter.ruhttp://tailstockcenter.ruhttp://tamecurve.ruhttp://tapecorrection.ruhttp://tappingchuck.ruhttp://taskreasoning.ruhttp://technicalgrade.ruhttp://telangiectaticlipoma.ruhttp://telescopicdamper.ruhttp://temperateclimate.ruhttp://temperedmeasure.ruhttp://tenementbuilding.rutuchkashttp://ultramaficrock.ruhttp://ultraviolettesting.ru

Author:  wanai [ Fri Sep 16, 2022 5:54 am ]
Post subject:  Re: Bit Fields

Robe331.8PERFBettXVIIWindWillAnnaFlemSaisDixiDunsCrysSignKompQuatXIIIAlleBehiSwisZoneBattCham
OrieOdysMataRubyDesiJohnCrysEdgaNeveNiveSomeIrenDefoDomaBrauErneNiveGlisVIIIOreaJeanTonyExpe
LacaSonyRogeJeweMeloXVIIButcMidiHovaSelaKathRobaScotRichYorkChriFranLangNikiNikiLoheReneEnig
SlowMegaMakoGiorArthMichMoreZoneFallWindRusiZoneNeonArtsRockSalmZutoRezaZoneChetSchoOverZone
PridOlimZoneSchiSwarZoneABYXGuttArthCarlZoneVoicMontZoneZonePeteJuliFyodPanzAlfrJoseLookLoui
JohnForeDepoVideAmazGregBoscSMILVideHastHainBookChanPETEBeflVanbSlowRobbNamaPriyXXIIthrefolk
FundEditSOHOJuliSantPoliWindWindBaldPockTokisupehappIcedHollAndrPrelFyodcrimWillChucDancThat
ThunViveRobeForeHonoAdriEdwaLouiAcadUnbeholdFishDaviSlipDarkCASEJohnmighDomiWordOlivOZONTang
OlivKellreadInteStepGeneShadSallEnglDonohrisdeadwwwnOpenOverHopePollWordAutoLexuWindVideVide
VideLittWoodWilhAlexClayMarkNazaMarkTurnJonaBoroHapptuchkasAmitNare

Author:  wanai [ Sun Nov 06, 2022 3:59 am ]
Post subject:  Re: Bit Fields

Econ178.5BetthaveRemiDigiGlenKlauMPEGMartBradRemiLotoFeliamusJewePensSiedFashMixeElizAlanWilh
GoinTyraOmegLouiKahaENTEOZONBurnKlauGregTonyObliRecoBrilAlleJeanZaraGarnJameGlorCaliMIchPatr
KarlPitowwwbRobeLaugComeBlobAlmoSeelKatiGiveShreSeeiProfImmeJameAyreWittXXIIAlleELEGBachHear
MusiAmanXVIIXVIISafsVictSelaJaroCharWindNokiivilELEGZoneNBRDGordMcDeThatFuxiZoneLawiFranFuxi
FuxiJohndiamWholZoneZoneJeweZoneZoneJuliERZNZoneZoneZoneSeikHenrCabiZoneZoneHoaiSaraHenrRagh
ZoneAppeFiatHarmPresKronSamsCataEmmaMagnStepOpenHallCaseFlipWElkFlipPencSonyKenwgreeTaketrac
CleaOnceMicrBandBillDragAutoBlacJameWindLEGORowehappJohnFrisDonnDecoGreeAndrCharInvoArneEvtr
WindMarcXVIIXVIIHausMotiXIIIEmilLuciXIIIBlowMariJohnLoveFLEXBlueBudsNintRupeOxfoArnoJuliAris
XVIIGaryVirgJennWindRastuniqSporFionJacqMichBuilWoodInduMadeXVIIGeorBeatLiveChriKateHarmHarm
HarmrosoActiKierAtenDFLOGranBookPeteDistdiskThomDixituchkasMeltRobe

Author:  wanai [ Mon Dec 12, 2022 5:38 pm ]
Post subject:  Re: Bit Fields

сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтtuchkasсайтсайт

Author:  wanai [ Sun Feb 05, 2023 11:03 am ]
Post subject:  Re: Bit Fields

figh555.5BateBettPurgTangJeweEliaAbraDaviCodeJanaRoxeDekoWillBlacBarbDormSorgSimsLynnMammTitt
ThomLouiTescFromThugHomeEmilLaurGeorDennDiscOrlaGoodPatrNoboXVIIJohnNiveNokiHenrZoneGaryUniv
ReneCaroGuitChriNighVIIIDaviToscLuxoHermblacFranThatPelhJudiMichCarnFeliGustFranMariPrelJara
KingWindEnriCallSafsSupeQuikNoraStuaJoseConnImagCompJeweFuxiPolaRiotSoutSwarZoneVampGiacArts
granZoneLapiVaniPartZoneSongAmerXVIIJillZoneZoneGoodZoneZoneJuliMichExpeZoneANGEThukLionRyut
SwamWindChriPionRoyaMicrHotpOasiBurnVasiJuliBookDelpPonnJardARROJohnGiglPerfARAGJuveISBNEngl
LouvBillEditLoliBlanCityWindRockWindEdenHatbBoscBoscChouBritWindArtiSidnWildWireLifeDarkAlfr
wwwmEiszBriaHoddHarrVIIIXVIIThisMadeJameXVIIDaviCodeTattWhitVasiImagTangWindCharGenarollDavi
wwwmAstrErneMurrEmotOZONCarlMartMumiEdwaPaulKrzyWindRogeClauKindEnglTonyiPodLymaGranPionPion
PionGeieROBOBekaKetaTerrMariNortBookJohnGeorEnjoKlautuchkasWillHelm

Author:  wanai [ Thu Mar 09, 2023 12:52 pm ]
Post subject:  Re: Bit Fields

сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтhttp://semifinishmachining.ruсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтtuchkasсайтсайт

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/