Redigerer
Sekstentallsystemet
Hopp til navigering
Hopp til søk
Advarsel:
Du er ikke innlogget. IP-adressen din vil bli vist offentlig om du redigerer. Hvis du
logger inn
eller
oppretter en konto
vil redigeringene dine tilskrives brukernavnet ditt, og du vil få flere andre fordeler.
Antispamsjekk.
Ikke
fyll inn dette feltet!
'''Sekstentallsystemet''', bedre kjent som '''det heksadesimale tallsystemet''', forkortet '''hex''', er et [[tallsystem]] med [[grunntall]] eller base 16. Navnet «heksadesimal» er en hybrid sammensatt av det [[Gammelgresk|greske]] ''hexa'' (έξι (exi)) for «seks» og ''decimal'' fra det [[latin]]ske ordet for «ti». Tallsystemet har 16 ulike siffer: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E og F. Det tallsystemet vi bruker til vanlig kalles [[titallsystemet]] eller det ''desimale'' system. De heksadesimale sifrene A, B, C, D, E og F representerer titallsystemets verdier 10, 11, 12, 13, 14 og 15. Når det er tale om ulike [[tallsystem]]er, bruker matematikere [[grunntall]]et (tallbasen) i senket skrift (subskript) etter tallet. Forrige setning kan da skrives slik: A<sub>16</sub> = 10<sub>10</sub>, B<sub>16</sub> = 11<sub>10</sub>, C<sub>16</sub> = 12<sub>10</sub>, D<sub>16</sub> = 13<sub>10</sub>, E<sub>16</sub> = 14<sub>10</sub>, F<sub>16</sub> = 15<sub>10</sub>. Grunntallet kan eventuelt skrives med bokstaver, på denne formen: A<sub>hex</sub> = 10<sub>dec</sub>. De første 32 positive heltallene skrives på følgende måte: {| class="wikitable" ! [[Titallsystemet]] (n<sub>10</sub>) | 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || '''10''' || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18 || 19 || '''20''' || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || '''30''' || 31 || 32 |- ! Sekstentallsystemet (n<sub>8</sub>) | 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 ||  A ||  B ||  C ||  D ||  E ||  F || '''10''' || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18 || 19 || 1A || 1B || 1C || 1D || 1E || 1F || '''20''' |} Det heksadesimale tallsystemet er meget nyttig i arbeid med [[datamaskin]]er. Årsaken er at det er nært forbundet med [[Binært tallsystem|totallsystemet]], bedre kjent som det ''binære'' tallsystemet, som datamaskiner er basert på. Sammenhengen er slik: Siden 16 = 2<sup>4</sup>, kan ethvert ''firesifret binært tall'' skrives som et ''ensifret heksadesimalt tall'' og omvendt. Fire [[bit]] (fire binære siffer) kan altså uttrykkes ved ett enkelt heksadesimalt siffer. (Se tabellen nedenfor.) En [[byte]] som består av 8 bit kan da kompakt angis med et tosifret heksadesimalt tall. Dette er en stor fordel for mennesker, som leser for eksempel «B4» mye lettere enn byten «10110100». == Titallsystemets 0–15 i fire ulike tallsystem== Tabellen nedenfor viser titallsystemets verdier 0–15 uttrykt i henholdsvis sekstentall-, titall-, åttetall- og totallsystemet. {| border="0" cellspacing="0" cellpadding="0" style="text-align:center;border:2px" |- style="background:black; height:2px" | style="background:black; width:2px" | || || || || || || || || || || || |-style="background:#FDC888; color:black; height:24px" | style="background:black; width:2px" | || style="width:45px"|'''0'''<sub>hex</sub> || = || style="width:45px"|0<sub>dec</sub> || = || style="width:45px"|0<sub>oct</sub> ||style="background:black; width:2px" | || style="background:white;width:24px"|0|| style="background:white;width:24px"|0|| style="background:white;width:24px"|0|| style="background:white;width:24px"|0 ||style="background:black; width:2px" | |-style="background:#E3EDE9; color:black; height:24px" | style="background:black; width:2px" | || '''1'''<sub>hex</sub> || = || 1<sub>dec</sub> || = || 1<sub>oct</sub> ||style="background:black; width:2px" | || style="background:white;width:24px"|0|| style="background:white;width:24px"|0|| style="background:white;width:24px"|0|| style="background:red;width:24px"|1||style="background:black; width:2px" | |-style="background:#E3EDE9; color:black; height:24px" | style="background:black; width:2px" | || '''2'''<sub>hex</sub> || = || 2<sub>dec</sub> ||= || 2<sub>oct</sub> ||style="background:black; width:2px" | || style="background:white;width:24px"|0|| style="background:white;width:24px"|0|| style="background:red;width:24px"|1|| style="background:white;width:24px"|0||style="background:black; width:2px" | |-style="background:#FDC888; color:black; height:24px" | style="background:black; width:2px" | || '''3'''<sub>hex</sub> || = || 3<sub>dec</sub> || = || 3<sub>oct</sub> ||style="background:black; width:2px" | || style="background:white;width:24px"|0|| style="background:white;width:24px"|0|| style="background:red;width:24px"|1|| style="background:red;width:24px"|1||style="background:black; width:2px" | |- style="background:black; height:2px" | style="background:black; width:2px" | || || || || || || || || || || || |-style="background:#E3EDE9; color:black; height:24px" | style="background:black; width:2px" | || '''4'''<sub>hex</sub> || = || 4<sub>dec</sub> ||= || 4<sub>oct</sub> ||style="background:black; width:2px" | || style="background:white;width:24px"|0|| style="background:red;width:24px"|1|| style="background:white;width:24px"|0|| style="background:white;width:24px"|0||style="background:black; width:2px" | |-style="background:#FDC888; color:black; height:24px" | style="background:black; width:2px" | || '''5'''<sub>hex</sub> || = || 5<sub>dec</sub> || = || 5<sub>oct</sub> ||style="background:black; width:2px" | || style="background:white;width:24px"|0|| style="background:red;width:24px"|1|| style="background:white;width:24px"|0|| style="background:red;width:24px"|1||style="background:black; width:2px" | |-style="background:#FEE978; color:black; height:24px" | style="background:black; width:2px" | || '''6'''<sub>hex</sub> || = || 6<sub>dec</sub> ||= || 6<sub>oct</sub> ||style="background:black; width:2px" | || style="background:white;width:24px"|0|| style="background:red;width:24px"|1|| style="background:red;width:24px"|1|| style="background:white;width:24px"|0||style="background:black; width:2px" | |-style="background:#E3EDE9; color:black; height:24px" | style="background:black; width:2px" | ||'''7'''<sub>hex</sub> || = || 7<sub>dec</sub> || = || 7<sub>oct</sub> ||style="background:black; width:2px" | || style="background:white;width:24px"|0|| style="background:red;width:24px"|1|| style="background:red;width:24px"|1|| style="background:red;width:24px"|1||style="background:black; width:2px" | |- style="background:black; height:2px" | style="background:black; width:2px" | || || || || || || || || || || || |-style="background:#E3EDE9; color:black; height:24px" | style="background:black; width:2px" | || '''8'''<sub>hex</sub> || = || 8<sub>dec</sub> || = || 10<sub>oct</sub> ||style="background:black; width:2px" | || style="background:red;width:24px"|1|| style="background:white;width:24px"|0|| style="background:white;width:24px"|0|| style="background:white;width:24px"|0||style="background:black; width:2px" | |-style="background:#FEE978; color:black; height:24px" | style="background:black; width:2px" | || '''9'''<sub>hex</sub> || = || 9<sub>dec</sub> ||= || 11<sub>oct</sub> ||style="background:black; width:2px" | || style="background:red;width:24px"|1|| style="background:white;width:24px"|0|| style="background:white;width:24px"|0|| style="background:red;width:24px"|1||style="background:black; width:2px" | |-style="background:#FDC888; color:black; height:24px" | style="background:black; width:2px" | || '''A'''<sub>hex</sub>|| = || 10<sub>dec</sub> || = || 12<sub>oct</sub> ||style="background:black; width:2px" | || style="background:red;width:24px"|1|| style="background:white;width:24px"|0|| style="background:red;width:24px"|1|| style="background:white;width:24px"|0||style="background:black; width:2px" | |-style="background:#E3EDE9; color:black; height:24px" | style="background:black; width:2px" | || '''B'''<sub>hex</sub>|| = || 11<sub>dec</sub> || = || 13<sub>oct</sub> ||style="background:black; width:2px" | || style="background:red;width:24px"|1|| style="background:white;width:24px"|0|| style="background:red;width:24px"|1|| style="background:red;width:24px"|1||style="background:black; width:2px" | |- style="background:black; height:2px" | style="background:black; width:2px" | || || || || || || || || || || || |-style="background:#FDC888; color:black; height:24px" | style="background:black; width:2px" | || '''C'''<sub>hex</sub>|| = || 12<sub>dec</sub> || = || 14<sub>oct</sub> ||style="background:black; width:2px" | || style="background:red;width:24px"|1|| style="background:red;width:24px"|1|| style="background:white;width:24px"|0|| style="background:white;width:24px"|0||style="background:black; width:2px" | |-style="background:#E3EDE9; color:black; height:24px" | style="background:black; width:2px" | || '''D'''<sub>hex</sub>|| = || 13<sub>dec</sub> ||= || 15<sub>oct</sub> ||style="background:black; width:2px" | || style="background:red;width:24px"|1|| style="background:red;width:24px"|1|| style="background:white;width:24px"|0|| style="background:red;width:24px"|1||style="background:black; width:2px" | |-style="background:#E3EDE9; color:black; height:24px" | style="background:black; width:2px" | || '''E'''<sub>hex</sub>|| = || 14<sub>dec</sub> ||= || 16<sub>oct</sub> ||style="background:black; width:2px" | || style="background:red;width:24px"|1|| style="background:red;width:24px"|1|| style="background:red;width:24px"|1|| style="background:white;width:24px"|0||style="background:black; width:2px" | |-style="background:#FDC888; color:black; height:24px" | style="background:black; width:2px" | || '''F'''<sub>hex</sub>|| = || 15<sub>dec</sub> || = || 17<sub>oct</sub> ||style="background:black; width:2px" | || style="background:red;width:24px"|1|| style="background:red;width:24px"|1|| style="background:red;width:24px"|1|| style="background:red;width:24px"|1||style="background:black; width:2px" | |- style="background:black; height:2px" | style="background:black; width:2px" | || || || || || || || || || || || |} == Omregning fra heksadesimalt til desimalt og omvendt == Vi vet fra vanlig titallsmatematikk at et flersifret tall, for eksempel 273, har følgende betydning: 273<sub>10</sub> = 2·10<sup>2</sup> + 7·10<sup>1</sup> + 3·10<sup>0</sup> = 200 + 70 + 3 = 273 Når man skal regne om (konvertere) et tall fra heksadesimalt til desimalt går man ut fra samme prinsipp: siffer nr. 1 bakfra skal multipliseres med grunntallet i nullte potens (16<sup>0</sup>=1), siffer nr. 2 med grunntallet i første potens (16<sup>1</sup>=16) osv. Å konvertere det heksadesimale 2D4 til desimalt blir da slik: 2D4<sub>16</sub> = (2·16<sup>2</sup> + 13·16<sup>1</sup> + 4·16<sup>0</sup>)<sub>10</sub> = 512<sub>10</sub> + 208<sub>10</sub> + 4<sub>10</sub> = 724<sub>10</sub> For å konvertere et tall fra titallsystemet til sekstentallsystemet må man gjentatte ganger utføre [[divisjon (matematikk)#Heltallsdivisjon|heltallsdivisjon]] med grunntallet 16 og merke seg resten, som vist i eksempelet med tallet 724 nedenfor: {| class="wikitable" style=text-align:center ! Heltalldivisjon !! Rest |- | 724/16 = 45 || align="center" | '''4''' |- | 45/16 = 2 || align="center" | '''13 = D<sub>16</sub>''' |- |  2/16 = 0 || align="center" | '''2''' |- | || align="center" | '''↑''' |} Så begynner man med restene nedenfra. Tallet 724 blir dermed 2D4<sub>16</sub> i sekstentallsystemet. ==Notasjon i ulike programmeringsspråk== Det er mange måter å betegne heksadesimale tall i ulike [[programmeringsspråk]]: * Ada og VHDL omslutter heksadesimale tall med «numeriske tegn», f.eks. «16#5A3#». (Merk: Ada godtar denne notasjonen for ''alle'' tallsystemer fra 2 til 16, for både [[heltall]] (integer) og [[flyttall]].) * [[C (programmeringsspråk)|C]], [[C++]] og andre språk med tilsvarende syntaks (sånn som [[Java (programmeringsspråk)|Java]]) prefikser heksadesimale tall med «0x», f.eks. «0x5A3». 0-tallet i startet blir brukt fordi tall må starte med et numerisk tegn, og «x» står for heksadesimal. * [[Pascal (programmeringsspråk)|Pascal]] og noen [[Assembler]]-kompilatorer indikerer heksadesimaler med en tilføyd «h» (hvis noen av tallene starter med en bokstav, så tilføyer man også «0» i starten), f.eks. «0A3Ch», «5A3h». * Andre assembler-kompilatorer ([[AT&T]], [[Motorola]]) og noen versjoner av [[BASIC]] bruker prefikset «$», f.eks. «$5A3». * Noen versjoner av [[BASIC]] prefikserer heksadesimale tall med «&h», f.eks. «&h5A3». * [[ActionScript]], programmeringsspråket til [[Adobe Flash]], omtaler heksadesimale tall med 0x, eks. 0xFFFFFF. Det finnes ingen enighet om en felles notasjonsstandard, så alle konvensjonene over er i bruk, noen ganger også i samme fremstillng. Forøvrig, siden det er få andre bruksområder for disse, byr dette på lite problemer. == Brøker == Sekstentallsystemet er bra til å lage brøker med (begge sider heksadesimaltallsuttrykk): :1/2 = 0,8 :1/3 = 0,5555... :1/4 = 0,4 :1/5 = 0,3333... :1/6 = 0,2AAAA... :1/8 = 0,2 :1/A = 0,19999... :1/C = 0,15555... :1/F = 0,1111... Fordi [[grunntall|tallbase]]n er kvadratisk, danner heksadesimaler oftere uløselige brøker enn titallsystemet. Repeterende desimaler oppstår når nevneren har en [[primfaktor]] som ikke finnes i telleren. I sammenheng med heksadesimale tall, gjelder dette hvis og bare hvis nevneren ikke er en toer-potens. Se [[tallsystem]]er for en oversikt over systemer med andre tallbaser. == Se også == * [[Webfarger]], også kalt heksadesimalfarger ==Referanser== <references/> {{Autoritetsdata}} [[Kategori:Tallsystemer]]
Redigeringsforklaring:
Merk at alle bidrag til Wikisida.no anses som frigitt under Creative Commons Navngivelse-DelPåSammeVilkår (se
Wikisida.no:Opphavsrett
for detaljer). Om du ikke vil at ditt materiale skal kunne redigeres og distribueres fritt må du ikke lagre det her.
Du lover oss også at du har skrevet teksten selv, eller kopiert den fra en kilde i offentlig eie eller en annen fri ressurs.
Ikke lagre opphavsrettsbeskyttet materiale uten tillatelse!
Avbryt
Redigeringshjelp
(åpnes i et nytt vindu)
Maler som brukes på denne siden:
Mal:Autoritetsdata
(
rediger
)
Modul:External links
(
rediger
)
Modul:External links/conf
(
rediger
)
Modul:External links/conf/Autoritetsdata
(
rediger
)
Modul:Genitiv
(
rediger
)
Navigasjonsmeny
Personlige verktøy
Ikke logget inn
Brukerdiskusjon
Bidrag
Opprett konto
Logg inn
Navnerom
Side
Diskusjon
norsk bokmål
Visninger
Les
Rediger
Rediger kilde
Vis historikk
Mer
Navigasjon
Forside
Siste endringer
Tilfeldig side
Hjelp til MediaWiki
Verktøy
Lenker hit
Relaterte endringer
Spesialsider
Sideinformasjon