đ° āļ¸ේ article āļāļෙāļą් āļāļා āļāļģāļą්āļąෙ float datatype āļāļෙāļą් āļŊිāļēāļą āļ āļāļēāļ් RAM āļāļේ store āˇෙāļŊා āļිāļēෙāļą්āļąෙ āļොāˇොāļ¸āļ¯ āļිāļēāļŊ āļāˇෙāļ¸ āļąැāļ්āļąāļ¸් float value āļāļāļ binary representation āļāļ āļොāˇොāļ¸āļ¯ āļිāļēෙāļą්āļąෙ āļිāļēāļŊා
---‐-----------------------------
āˇāļģි, Java āˇāļŊ whole numbers āļāˇෙāļ¸ āļąැāļ්āļāļ¸් āļ´ූāļģ්āļĢ āˇංāļ්āļēා āļąිāļģූāļ´āļĢāļē āļāļģāļą්āļą data types 4 āļ් āļිāļēෙāļąāˇා
1. Byte (8bits)
2. Short (16bits)
3. Int (32bits)
4. Long (64bits)
☆ āļ¸ේ datatypes āˇāļŊ positive āˇා negative numbers āļąිāļģූāļ´āļĢāļē āļāļģāļą්āļą āļිāļēෙāļą technique āļāļ āļāļ¸ා 2's complement āļිāļēāļą්āļąෙ āˇැāļļැāļēි āļ āļ´ි āļ¸ේ āļāļා āļāļģāļą්āļą āļēāļą float āˇා double datatypes āˇāļŊ RAM representation āļāļ āļ āļිāļēāļą්āļąෙ float āˇāļģි double āˇāļģි variable āļāļāļāļ§ assign āļāļģāļą value āļāļāļ් RAM āļāļෙ store āˇෙāļŊා āļිāļēෙāļą āˇිāļ¯ිāļē āļāļŊිāļą් āļ āļ´ි āļāļා āļāļģāļ´ු int,short,long,byte āˇāļේ datatype āˇāļŊ variable āļāļāļ store āˇෙāļŊා āļිāļēෙāļą value āļāļāļ§ āˇāļŠා āļāļģāļ¸āļ් āˇෙāļąāˇ්
đ° float āļāļāļ āˇāļģි double āļāļāļිāļą් āˇāļģි āˇංāļ්āļēාāˇāļ් āļŊිāˇුāˇāļ¸ apparently, āļ āļ´ිāļ§ āļ¯āļිāļą්āļą āļිāļēෙāļą āˇෙāļąāˇ āļāļ¸ා float value āļāļāļ් 'f' āļāļāļිāļą් āļ āˇāˇāļą් āˇෙāļąāˇා āˇැāļļැāļēි double value āļāļāļ් normally āļ āļ´ි āļŊිāļēāļą āļ¯āˇāļ¸ āˇංāļ්āļēාāˇāļ් āˇිāļ¯ිāļēāļ§ āļ āˇāˇāļą් āˇීāļ¸
float number1 = 35.35f; //float
double number2 = 35.35; //double
āļāļē āˇිāļ¯ිāļēāļ§ āļāļ¸ා Java āˇāļŊ float āˇා double values āļąිāļģූāļ´āļĢāļē āļāļģāļą්āļąෙ
đ°āļ āļąිāļ් āļāļ āļāļ¸ා bit allocation āļāļ. Float āˇāļŊ āļ āļāļēāļ් āļąිāļģූāļ´āļĢāļē āļāļģāļą්āļą RAM āļāļෙ bit 32(4 bytes) āļāļą āˇෙāļąāˇා āļāļāļොāļ§ double value āļāļāļ් āļąිāļģූāļ´āļĢāļē āļāļģāļą්āļą bit 64(8bytes) āļāļą āˇෙāļąāˇා
đ°āļāļāļොāļ§ āļෙāļąෙāļ්āļ§ āˇිāļෙāļą්āļą āļ´ුāļŊුāˇāļą් int datatype āļāļෙ bit 32 long datatype āļāļේ bit 64 āļēිāļąෙ āļ āˇිāļą්āļ¯ āļ¸ේ datatypes āˇāļŊ RAM representation āļāļ āļ´ිāļŊිāˇෙāļŊිāļą් float āˇා double āˇāļŊ representation āļāļāļ§ āˇāļ¸ාāļą āˇෙāļą්āļąෙ āļąැāļ¯්āļ¯ āļිāļēāļŊ (eventhough they have floating point values).
āˇැāļļැāļēි āļāˇෙāļ¸ āˇෙāļą්āļąෙ āļąෑ
đint value āļāļāļ binary representation āļāļ āļ´ොāļŠ්āļŠāļ් āļļāļŊāļ¸ු
Eg:-
đĸ+10
0 0000000000000000000000000001010
|
|-》sign bit
đĸ -10
1 1111111111111111111111111110101
|
|-》sign bit
đLong āˇāļŊāļ් āļāļē āˇිāļ¯ිāļēāļ§ āļāļ¸ා 2's complement āˇāļŊāļ§ āļēāļą්āļąෙ āˇැāļļැāļēි bit allocation āļāļ āˇිāļāļģāļ් āˇෙāļąāˇ් āˇෙāļąāˇා
đ°āˇāļģි āļ¯ැāļą් āļ āļ´ිāļ§ āļ āˇāļļෝāļ°āļēāļ් āļිāļēෙāļąāˇා āļොāˇොāļ¸āļ¯ int,long āˇāļŊිāļą් positive āˇා negative numbers binary represent āļāļģāļą්āļąෙ āļිāļēāļŊා
āļ¯ැāļą් āļ āļ´ි āļ¸ාāļෘāļාāˇāļ§ āļāļ¸ු.
-------‐-------------------------
⚙️ āļ¸ුāļŊිāļą්āļ¸ āļ āļ´ි āļāļා āļāļģāļ¸ු float datatype āļāļāļිāļą් āļŊිāļēāļ´ු value āļāļāļ binary āļąිāļģූāļ´āļĢāļē āļොāˇොāļ¸āļ¯ āļිāļēāļŊ
(See image 2)
āˇāļģි āļāļāļොāļ§ float āļāļāļිāļą් number āļāļāļ් āļŊිāˇුāˇāˇāļ¸ create āˇෙāļą binary number āļāļෙ structure āļāļ āļāļ¸ා āļāļē āļිāļēෙāļą්āļąෙ (āļ´ේāļąāˇāļąෙ āļāļŊිāļą් āļāļා āļāļģāļ´ු datatypes 4 āˇāļŠා structure āļāļ āļ´ොāļŠ්āļŠāļ් āˇෙāļąāˇ් āļිāļēāļŊා ) āļ¸ේ āļ§ිāļ āļ āļ´ි āļāļිāļą් āļāļ breakdown āļāļģāļāļ¸ු.
đ Eg:- 4.15f
āļāļŠ āļිāļēෙāļą float number āļāļ āļāļ¸ා āļ āļ´ි āˇැāļŠේāļ§ āļāļą්āļąෙ
đ° 1st Step:-
Convert the decimal number in to its binary number
āļ āļිāļēāļą්āļąෙ 10 āļ´ාāļ¯āļēෙāļą් āļ āļ´ි āļŊāļ āļිāļēෙāļą āˇංāļ්āļēා⎠2 āļ´ාāļ¯āļēāļ§ āļ´āļģිāˇāļģ්āļāļąāļē āļāļģāļāļą්āļą āļāļą āļāļāļොāļ§ āļāļą āļ āļāļē
100.0010011
đ°2nd step:-
Normalize the binary number
āļ āļිāļēāļą්āļąෙ āļ āļ´ි āļ āļ¯ාāļŊ āļ¯්āˇිāļ¸āļē āˇංāļ්āļēා⎠scientific notation āļāļāļ§ āļŊිāļēාāļāļą්āļą āļāļą. Scientific notation āļිāļēāļą්āļąෙ āļāļා āˇිāˇාāļŊ āˇංāļ්āļēාāˇāļ් āļąැāļ්āļāļ¸් āļāļා āļුāļŠා āˇංāļ්āļēාāˇāļ් āļ āļ´ිāļ§ manage āļāļģāļāļą්āļą āļ´ුāļŊුāˇāļą් āˇිāļ¯ිāļēāļ§ āļ āļිāļēāļą්āļąේ
Calculations āļāļģāļą්āļą, āļ āļąිāļ් āˇිāˇාāļŊ āˇෝ āļුāļŠා āˇංāļ්āļēාāˇāļą් āļāļ්āļ āˇංāˇāļą්āļ¯āļąāļē āļāļģāļą්āļą āļ´ුāļŊුāˇāļą් āˇිāļ¯ිāļēāļ§ āˇāļ¯ාāļāļą්āļą āļāļ. āļāļිāļą් Scientific notation āļāļāļ§ āļāļąāļ¸ āļ´ාāļ¯āļēāļ්(base) āļāļ්āļ āˇැāļŠ āļāļģāļą්āļą āļ´ු⎠ුāˇāļą්.
100.0010011 --> 1.000010011 × 2²
āļāļē āļිāļēෙāļą්āļąෙ āļ āļ´ි āˇāļ¯ාāļāļ්āļ binary number āļāļේ scientific notation āļāļ. āļāļෙ āļ āļ´ි 2 āļļāļŊāļē 2 āˇිāļ¯ිāļēāļ§ āļ āļ´ි āļŊිāļēāļŊ āļිāļēෙāļąāˇāļąෙ āļ āļ¯ාāļŊ āˇංāļ්āļēාāˇ, āļāļෙ power āļāļāļ§ āļąැāļ්āļāļ¸් āļļāļŊāļēāļ§ āļāļ¸ා exponent āļිāļēāļŊ āļිāļēāļą්āļąෙ(āļ¸āļą් āˇිāļāļąāˇා image 2 āļāļේ exponent āļිāļēāļą āļොāļ§āˇ āļැāļą āļ´ොāļŠි idea āļāļāļ් āļāļą්āļą āļāļි āļිāļēāļŊා. Float āļāļāļ exponent āļāļāļ§ āļ āļ´ි bit 8āļ් āˇෙāļą් āļāļģāļąāˇා )
đ°āļāļāļොāļ§ āļāļēි āļ āļ´ි power āļāļāļ§ āˇිāļ¯ිāļēāļ§ 2 āļ¯ැāļ¸්āļ¸ෙ . āļāļāļ§ āˇේāļු⎠āļāļ¸ා 100.0010011 value āļāļේ bits āļ¯ෙāļāļ් left side āļāļāļ§ shift āļāļģāļ´ු āļāļ.
āļ¸ේ scientific notation āļāļ āļේāļģුāļ¸් āļāļą්āļą āļ´ොāļŠි example āļāļāļ් āļļāļŊāļ¸ු.
Eg:- 10.75 base 10
āļ¸ේāļ 10 āļ´ාāļ¯āļēේ āˇංāļ්āļēාāˇāļ් . āļ¸ේ āˇංāļ්āļēා⎠āļ āļ´ි scientific notation āļāļෙāļą් āļŊිāˇ්āˇොāļ් āļāļą්āļąෙ
1.075 × 10¹
đ°10¹ āļිāļēāļą්āļąෙ 10 āļąෙ āļොāˇොāļ¸āļ්. āļāļāļොāļ§ 10 × 1.075 āļāļ්āļāļģේ āļāļą්āļąෙ 10.75. āļ¸ේ āˇිāļ¯ිāļēāļ§āļ¸ āļāļ¸ා āļ āļ´ි āļāļŊිāļą් binary number āļāļ scientific notation āļāļāļ§ āˇāļģāˇāļāļ්āļෙ (but in base 2)
đ°likewise computer āļāļ āˇැāļŠ āļāļģāļą්āļąෙ machine language (0,1) āļāļ්āļ āˇිāļą්āļ¯ා āļ āļ´ි binary scientific notation āļāļ use āļāļģා.
āˇāļģි āļ¯ැāļą් āļ āļ´ි 3rd step āļāļāļ§ āļēāļ¸ු.
đ°3rd step :-
Add a bais value to exponent
āļ āļ´ිāļ§ float,double āˇāļŊ negative numbers represent āļāļģāļą්āļą 2's complement āļˇාāˇිāļා āļāļģāļą්āļąෙ āļąෑ āļ āˇෙāļąුāˇāļ§ IEE 754 format āļ¸āļ āļ´āļ¯āļąāļ¸් āˇෙāļ ්āļ sign- magnitude system āļāļāļ් āļāļ¸ා use āļāļģāļą්āļąෙ. Bais āļිāļēāļŊ āļිāļēāļą්āļąෙ negative āˇා positive exponent āļąිāļģූāļ´āļĢāļē āļāļģāļą්āļą use āļāļģāļą concept āļāļāļ්
(āļොāˇොāļ¸āˇāļģි bais āļිāļēāļŊා āˇංāļāļŊ්āļ´āļēāļ් āļිāļēෙāļąāˇා āļිāļēāļŊා idea āļāļāļ් āļිāļēෙāļą්āļą āļāļą)
āļ¸ේ bais āļිāļēāļą value āļāļ āļąිāļāļ¸් constant āļāļāļ්(āļąිāļēāļāļēāļ්) āˇāļේ āˇැāļ¸ float value āļāļāļāļ¸ bais values āļāļ constant āļ āļāļēāļ් . Bais āļāļ āˇොāļēāļą්āļą āļ´ොāļŠි formula āļāļāļ් āļිāļēෙāļąāˇා.
đBais value = 2(n-1) -1
⭕️Note : (n-1) āļිāļēāļą්āļąෙ 2 power āļāļ
đ°āļāļāļොāļ§ n āļිāļēāļą්āļąෙ exponent āļāļෙ bit āļāļĢāļą. float āˇāļŊ exponent āļāļේ bit 8 āˇිāļą්āļ¯ n āˇāļŊ āļ āļāļē 8. āļāļāļොāļ§ āļ āļ´ේ bais value āļāļ
= 2(n-1) -1
= 2(8-1) -1
= 2 ⁷ -1
= 128 -1
= 127
đ° 4th step :-
Final step āļāļ āļāļ¸ා exponent āļāļ noramlize āļිāļģීāļ¸. āļ āļිāļēāļą්āļąෙ āļ āļ´ි āļා⎠āļිāļēෙāļą exponent value āļāļ(2) āļ āļ´ි āˇāļ¯ාāļāļ්āļ bais value āļāļāļ§(127) āļāļāļු āļāļģāļą්āļą āļāļą
đNormalized = Actual exponent + bais
Exponent
= 2 + 127
= 129
đ°Exponent āļāļ noramlize āļāļģāļą්āļąෙ positive āˇා negative exponent use āļāļģāļą්āļą āļ´ුāļŊුāˇāļą් āˇෙāļą්āļą
----------------------------------
đ°āļ¯ැāļą් āļ āļ´ි āļා⎠āļāļą āļāļģāļą items āļāļ්āļොāļ¸ āˇāļේ āļිāļēෙāļąāˇා
1) sign bit āļāļ 0(since 4.15 '+' number)
2) Exponent value āļāļ(10000001)
āļāļ් āļāļ්āļāļ¸ āļ āļ´ි image 2 āļāļේ āļāļා āļāļģāļ´ු Mantissa āļāˇෙāļ¸ āļąැāļ්āļāļ¸් significand part āļāļāļ් āļිāļēෙāļąāˇා
1.000010011 × 2² value āļāļෙ .000010011 āļāļ¸ා Mantissa āļිāļēāļą්āļąෙ.
đ°āļ¸ෙāļāļąāļ¯ි āļ āļ´ි dot(.) āļāļāļ§ āļāļŊිāļą් āļිāļēෙāļą 1 āļąොāˇāļŊāļා āˇāļģිāļąāˇා āļ¸ොāļāļ¯ āļ āļ´ි binary value āļāļāļ් noramlize āļāļģāļ¯්āļ¯ි
'1' āļāļ¸ා āļ¸ුāļŊāļ§ āļāļą්āļąෙ
đ°āˇැāļļැāļēි Mantissa āļāļෙ bit 23 āļිāļēෙāļąāˇāļąෙ Float āļāļāļ§ āļ āļ¯ාāļŊ⎠āļ āˇිāļą්āļ¯ා āļ āļ´ි āļāļŊිāļą් Mantissa eket assign āļāļģāļ´ු 000010011 set āļāļේ āļāļුāļģු bit āļ§ිāļāļ§ '0' assign āļāļģāļąāˇා
đ°So finally. Binary representation of 4.15f will be
0 10000001 00001001100000000000000





No comments:
Post a Comment