Sie sind auf Seite 1von 4

23/11/2016

MemoryAddressCalculationinanArrayGuideForSchool

Memory Address Calculation in an Array

70

Facebook

Twitter

Subscribe

SHARES

AddressCalculationinsingle(one)DimensionArray:

ArrayofanelementofanarraysayA[I]iscalculatedusingthefollowingformula:

AddressofA[I]=B+W*(ILB)

Where,
B=Baseaddress
W=StorageSizeofoneelementstoredinthearray(inbyte)
I=Subscriptofelementwhoseaddressistobefound
LB=Lowerlimit/LowerBoundofsubscript,ifnotspecifiedassume0(zero)

Example:

GiventhebaseaddressofanarrayB[1300..1900]as1020andsizeofeachelementis2bytesinthememory.FindtheaddressofB[1700].

Solution:

Thegivenvaluesare:B=1020,LB=1300,W=2,I=1700

AddressofA[I]=B+W*(ILB)

=1020+2*(17001300)
=1020+2*400
=1020+800
=1820[Ans]

AddressCalculationinDouble(Two)DimensionalArray:

http://www.guideforschool.com/625348memoryaddresscalculationinanarray/

1/4

23/11/2016

MemoryAddressCalculationinanArrayGuideForSchool

Whilestoringtheelementsofa2Darrayinmemory,theseareallocatedcontiguousmemorylocations.Therefore,a2Darraymustbelinearizedsoas
toenabletheirstorage.Therearetwoalternativestoachievelinearization:RowMajorandColumnMajor.

AddressofanelementofanyarraysayA[I][J]iscalculatedintwoformsasgiven:
(1)RowMajorSystem(2)ColumnMajorSystem

RowMajorSystem:

TheaddressofalocationinRowMajorSystemiscalculatedusingthefollowingformula:

AddressofA[I][J]=B+W*[N*(ILr)+(JLc)]

ColumnMajorSystem:

TheaddressofalocationinColumnMajorSystemiscalculatedusingthefollowingformula:

AddressofA[I][J]ColumnMajorWise=B+W*[(ILr)+M*(JLc)]

Where,
B=Baseaddress
I=Rowsubscriptofelementwhoseaddressistobefound
J=Columnsubscriptofelementwhoseaddressistobefound
W=StorageSizeofoneelementstoredinthearray(inbyte)
Lr=Lowerlimitofrow/startrowindexofmatrix,ifnotgivenassume0(zero)

http://www.guideforschool.com/625348memoryaddresscalculationinanarray/

2/4

23/11/2016

MemoryAddressCalculationinanArrayGuideForSchool

Lc=Lowerlimitofcolumn/startcolumnindexofmatrix,ifnotgivenassume0(zero)
M=Numberofrowofthegivenmatrix
N=Numberofcolumnofthegivenmatrix

Important:Usuallynumberofrowsandcolumnsofamatrixaregiven(likeA[20][30]orA[40][60])butifitisgivenasA[LrUr,Lc
Uc].Inthiscasenumberofrowsandcolumnsarecalculatedusingthefollowingmethods:

Numberofrows(M)willbecalculatedas=(UrLr)+1
Numberofcolumns(N)willbecalculatedas=(UcLc)+1

Andrestoftheprocesswillremainsameasperrequirement(RowMajorWiseorColumnMajorWise).

Examples:

Q1.AnarrayX[15.10,1540]requiresonebyteofstorage.Ifbeginninglocationis1500determinethelocationofX[15][20].

Solution:

Asyouseeherethenumberofrowsandcolumnsarenotgiveninthequestion.Sotheyarecalculatedas:

NumberorrowssayM=(UrLr)+1=[10(15)]+1=26
NumberorcolumnssayN=(UcLc)+1=[4015)]+1=26

(i)ColumnMajorWiseCalculationofaboveequation

Thegivenvaluesare:B=1500,W=1byte,I=15,J=20,Lr=15,Lc=15,M=26

AddressofA[I][J]=B+W*[(ILr)+M*(JLc)]

=1500+1*[(15(15))+26*(2015)]=1500+1*[30+26*5]=1500+1*[160]=1660[Ans]

(ii)RowMajorWiseCalculationofaboveequation

Thegivenvaluesare:B=1500,W=1byte,I=15,J=20,Lr=15,Lc=15,N=26

AddressofA[I][J]=B+W*[N*(ILr)+(JLc)]

=1500+1*[26*(15(15)))+(2015)]=1500+1*[26*30+5]=1500+1*[780+5]=1500+785
=2285[Ans]

MoreQuestionstofollow

StartDownloadViewPDF
ConvertFromDoctoPDF,PDFtoDocSimplyWithTheFreeOnlineApp!Gotofromdoctopdf.com

Related

http://www.guideforschool.com/625348memoryaddresscalculationinanarray/

3/4

23/11/2016

MemoryAddressCalculationinanArrayGuideForSchool

Related

HowtoSortaTwoDimensional(2D)Array
November8,2013
In"ArrayRelatedPrograms"

JavaProgramtoMultiplyTwoMatrices
[MatrixMultiplication]
February13,2015
In"ArrayRelatedPrograms"

JavaProgramtoprintBoundaryElementsof
a2DArray
February18,2014
In"ArrayRelatedPrograms"

http://www.guideforschool.com/625348memoryaddresscalculationinanarray/

4/4

Das könnte Ihnen auch gefallen