Anda di halaman 1dari 21

Computer Languages

Machine Language A collection of binary numbers


Not standardized. There is a different machine language for
every processor family.

Assembly Language - mnemonic codes that corresponds


to machine language instructions.
Low level: Very close to the actual machine language.

High-level Languages - Combine algebraic expressions


and symbols from English
High Level : Very far away from the actual machine language
For example: Fortran, Cobol, C, Prolog, Pascal, C#, Perl, Java.

Example of Computer
Languages
C Source Code:

char name[40];
printf("Please enter your name\n");
scanf("%s", name);
printf("Hello %s", name);

Assembly Code:

push
offset string "Please enter your name\n"
(41364Ch)
call
dword ptr [__imp__printf (415194h)]
add
esp,4
lea
eax,[name]
push
eax
push
offset string "%s" (413648h)
call
dword ptr [__imp__scanf (41519Ch)]
add
esp,8
lea
eax,[name]
push
eax
push
offset string "Hello %s" (41363Ch)
call
dword ptr [__imp__printf (415194h)]
add
esp,8

Machine Code:

68 4C 36 41 00 FF 15 94 51 41 00 83 C4 04 8D 45 D8
50 68 48 36 41 00 FF 15 9C 51 41 00 83 C4 08 8D 45
D8 50 68 3C 36 41 00 FF 15 94 51 41 00 83 C4 08

NUMBER SYSTEM
A number system is a system of numbers used to count
things. Numbers are arranged to count things.
Types of Number System:
(1) Positional Number System:The number system in which
the weight of each digit depends on its relative position
within the number , is called positional number system.
(2) Non-Positional Number system: Such type of system is
used when human being counted with fingers, sticks etc.
Arithmetic operations are difficult to perform in such a
system.

Type of Positional Number Systems


(1) Decimal Number System( base 10)
(2) Binary Number System( base 2)
(3) Octal Number System (base 8)
(4) Hexadecimal Number System (base 16)
Note: The base or radix of a number system
is defined as number of digits it uses to
represent numbers in the system.

Decimal Number System


Decimal number system uses 10 digits, from
0 to 9,to represent number. So, its base or
radix is 10.

Continued
Weight of n th digit of a number from right
hand side=nth digit x (Base)n-1
(6498)10=8x100+9x101+4x102+6x103

Binary Number System


The base of the binary number system is 2.
It uses only two digits,0 and 1. In short, a
binary digit is called a bit.
(1101)2=1x20+0x21+1x22+1x23=(13)10

Conversion of a Decimal Number to


Binary Number
Illustrative Example:(41)10=(101001)2

Quotient

Remainder

41/2=20

1(LSB)

20/2=10

10/2=5

5/2=2

2/2=1

=0

1(MSB)

Conversion Of D Fraction to B
Fraction (0.8125) 10=(0.1101)2
F

Fx2

New F

Integer

0.8125

1.625

0.625

1(MSB)

0.625

1.25

0.25

0.25

0.50

0.50

0.50

1.00

0.00(stop )

1(LSB)

Continued
In a particular case, it may be possible that
the fraction has not become zero and the
process will continue further. For such a
case ,an approximation is made. . Now
you can take your result upto 6 or desired
pure places after the binary point.
Exercise: (12.625)10=(?)2

Conversion of B number to decimal


Number
(101)2=1x20+0x21+1x22
(1011)2=1x20+1x21+0x22+1x23=(11)10

Conversion of B fraction to D
fraction
(0.1101)2=1x2-1+1x2-2+0x2-3+1x2-4
=0.5+0.25+0+0.0625
=(0.8125)10

Octal Number System


The base of octal number system is 8. It uses 8 digits 0,1,2,3,4,5,6 and
7. The decimal number (8)10 is represented by (10)8,(9)10 by (11)8
and so on. As 8 =23,an octal number is represented by a group of
three binary bits.
For example, 4 is represented by 100,6 by 110.
If an octal number contains two or more than two digits, then each digit
is individually represented by a group of three binary bits. Then such
a binary representation of octal number is called binary coded octal
number.
(46)8=(100 110)2

Conversion of Decimal number to


Octal Number
(62)10=(76)8.

Quotient

Remainder

62/8=7

6(LSD)

7/8=0

7(MSD)

Conversion of D Fraction to Octal


Fraction (0.96)10=(0.75341)8
F

Fx8

Remainder Integer
F

0.96

7.68

0.68

7(MSD)

0.68

5.44

0.44

0.44

3.52

0.52

0.52

4.16

0.16

0.16

1.28

0.28

1(LSD)

Conversion Of Octal Number to


Decimal Number
(364)8=4x80+6x81+3x82
=192+48+4
=(244)10
Conversion of Octal Fraction to Decimal
Fraction:
(0.563)8=5x8-1+6x8-2+3x8-3
=0.625+0.09375+0.005859375
=(0.724609375)10

Hexadecimal Number
The base in hexadecimal number system is 16. Its digits
from 0 to 9 are same as those used by decimal number
system. In that system 10 is represented by A,11 by B,12
by C,13 by D,14 by E and 15 by F. The decimal number
16 is represented by 10,17 by 11 and so on in
hexadecimal.
A hexadecimal digit is represented by four binary bits. For
example 5 is represented by 0101.
If a hexa-decimal number consists of more than 1 digit,
then each digit is represented by group of 4 binary bits.
(86)16=(1000 0110)2

Conversions
All conversions follow the same process as
that of octal .
Change 8 with 16 here.

Miscellaneous Conversions
Conversion of a binary number to Octal
Number:- For binary to octal conversion,
group of 3 binary bits each are formed in
the binary number. After forming the
groups, each group of 3 binary bits is
converted to its octal equivalent.
(101110)2=(101 110)=(56)8

Other Examples
(1101011)2= (1) (101) 011)
=(001)(101)(011)
=(153)8
(1011.1011)2=(1)(011).(101)(1)
=(001)(011).(101)(100)
=(13.54)8
Similarly, such conversions are made in
case of binary and hexadecimal numbers.

Conversion of Octal to Binary


number
(376)8=(011)(111)(110)
=(011111110)2
=(11111110)2
(56.34)8=(101)(110).(011)(100)
=(101110.011100)2
=(101110.01111)2
Similarily conversions from hexa-decimal to binary can be performed.

Anda mungkin juga menyukai