0% found this document useful (0 votes)
184 views

Memory Address Calculation in An Array - Guide For School

This document discusses how to calculate memory addresses for elements in single-dimensional and two-dimensional arrays. For single-dimensional arrays, the address is calculated using a base address, element size, subscript, and lower bound. For two-dimensional arrays, addresses can be calculated row-major or column-major using a similar formula involving the base address, element size, row and column subscripts, and row and column lower bounds. An example calculates the address of an element in a 2D array given various parameters of the array.

Uploaded by

vivek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
184 views

Memory Address Calculation in An Array - Guide For School

This document discusses how to calculate memory addresses for elements in single-dimensional and two-dimensional arrays. For single-dimensional arrays, the address is calculated using a base address, element size, subscript, and lower bound. For two-dimensional arrays, addresses can be calculated row-major or column-major using a similar formula involving the base address, element size, row and column subscripts, and row and column lower bounds. An example calculates the address of an element in a 2D array given various parameters of the array.

Uploaded by

vivek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like