Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 80

Problem Solving using UNIT II

Computer Programming NUMBERS AND


MEMORIES

© Kalasalingam academy of research and education


Syllabus
Week 4:

Unit 2
Outcomes
Students could be able to understand the
background of values and their memories

© Kalasalingam academy of research and education COURSE NAME


Unit 2 Outline

Lesson 1. Type lesson name (part of unit)

Lesson 2. Type lesson name (part of unit

Lesson 3. Type lesson name (part of unit

Lesson 4. Type lesson name (part of unit

Lesson 5. Type lesson name (part of unit)

© Kalasalingam academy of research and education COURSE NAME


Course Progress

W
e
e
k

4
.

I
n
f
o
r
m
a
t
i
o
n

t
o

D
a
t
a

F
o
r
m
a
t

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking

Mathematical thinking fundamental ideas in Mathematics

Statistical thinking The core of statistics

Computational Thinking Basic notations of Computer Science

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking
• Computational Thinking teaches the use of abstraction and decomposition when solving complex
problems;

• it presents a framework for understanding algorithms; and it describes essential concepts in dealing with
data and code and in expressing the limits of modern computing machinery.

• Computational Thinking is a relatively recent proposition;

• Using Computational Thinking, able to apply basic strategies in problem solving, understand the
character of a solution or algorithm, and have a sense of the ways in which computerization and
digitization have changed how research is conducted.

• “Computational Thinking” as a major framing device to present core ideas in Computer Science.

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking

The following are the parts of Computational Thinking.

1. Data Format and Representation


2. Modes of Data Collection
3. Algorithmic Analysis

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking
1. Data Format and Representation
• The different forms that data take on as they are stored, processed, and shared, including but not limited
to the differences between: binary, plain text, human readable, comma delimited, and self-describing
formats.
• Different forms of data lend themselves to different forms of analysis, often with tradeoff between
legibility and processing.
• Data used to be mostly about processing, but now it is as much about sharing and publishing, both
through simple posting of files for download and viewing using a program that interprets the file
format, as well as through creation of feeds that push out updates from a data source in real-time.
• Data representation is a key construct for applying computational thinking to problems at every scale.

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking

1. Data Format and Representation


• For example, recycling, safety, asthma, stress/chill, and daily habits will be centered around tagged
images, while transportation, and exercise, center around activity traces.
• This gives us the opportunity to talk about the different ways we represent images, text, and location
time series, and the different ways we manage and process the data.
• The fact that the campaigns have multiple types of data lets us use those differences to understand
how format and representation play an important role in computing systems.

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking

2. Modes of Data Collection


• From this, Both purposeful hypothesis-driven data collection and data exploration will understand easily.
• Purposeful data collection includes surveys and designed experiments and is the more traditional mode.
• Increasingly, knowledge is equally being created through the exploration of otherwise-reported and available
data to extract patterns, correlations, and even causations.
• Understanding exploratory data analysis is a key construct in applying computational thinking to the real
world.

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking
2. Modes of Data Collection
• It gives opportunities for both hypothesis driven and exploratory modes of data collection.
• Take transportation, as an example.
• Students can do an exploratory exercise looking at how students in their class get to and from college
and then investigate the data for correlations, trends, and clustering as to the patterns of transport
and available demographic information
Or
• One can present a hypothesis driven approach where you explore the extent to which mode of
transportation trends toward independent transport differently for different genders.
• Similar contrasts can be presented across the environmental and personal campaigns.
• For example, a student might explore the relationship between sleep patterns during the week and
exercise on the weekend, with the hypothesis that lack of sleep during the week contributes to reduced
physical activity on the weekend.

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking

3. Algorithmic Analysis
• The Analysis of algorithms can learn by constructing algorithms that iteratively process data, and
whose logic is based on the results of previous steps in the processing,
• So, we can build the algorithms to do exploratory data analysis, for example using constructs such as
decision trees and multi-dimensional scaling.
• These are algorithms that have informal descriptions and whose understanding will provide the
students both with key analytical tools, as well as with the insight into how those tools work.
• The data is not just about one-shot (if complex) mathematical functions applied to data, but rather
about algorithmically defined programs that branch and loop over the data to extract knowledge.

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking

3. Algorithmic Analysis
• Within each of those campaigns there will be opportunities to both do direct analysis and then follow it with
algorithmic analysis in order to expose more complex and telling relationships.
• For example, students might be taught how to construct a decision tree to process and classify GPS time
series into activities, such as still, driving, and walking.
• The power of introducing decision trees is that they have a graphical as well as a predictive structure and the
relation between algorithms and mathematics behind is possible.
• Take a look at the structure and details of the decision tree and build an understanding for the algorithm.

© Kalasalingam academy of research and education COURSE NAME


Computational Thinking

3. Algorithmic Analysis
Example:
• Like the game of 20 questions, a decision tree is a series of splittings:
• The first split might be whether the person’s speed is greater than 25 miles an hour or not;
• A second might be whether they are near a freeway;
• A third might be based on what the person was doing in the previous time-slot, and so forth.
• Such algorithmic analysis is at the heart of data practices, modeling and many other aspects of modern
computer science.
• From this, we can see how it relates to important environmental and personal issues, and how it gets
applied to very personal instantiations of that data.

© Kalasalingam academy of research and education COURSE NAME


Information
Introduction:

• The Sequence of the Instruction written to perform specific task is called the Program.
• This Instructions are formed using special symbols and words according to some rigid rule is known as
syntax rules.
• Every Instruction must be written according to the syntax rule of the languages.
• Like any other languages C languages has its vocabulary and grammar. They are follow up for making
the program.

© Kalasalingam academy of research and education COURSE NAME


Information

Character Set:
⚫ Character Set is the set of the character.
⚫ This characters are used to form the word, numbers and expression.
⚫ The characters in the c are grouped into the following categories.
 Letters : Uppercase A…Z, Lowercase a…z
 Digits : All decimal digits 0 to 9
 Special Character : ,(comma) .(period) ; (semicolon) :(colon), & (ampersand), # (number sign) etc.
 White spaces : Blank Space, Horizontal Space, New Line.

© Kalasalingam academy of research and education COURSE NAME


Information

C Tokens:
⚫ Smallest Individual units are known as C Tokens.
⚫ There are six types of the C Tokens.
 Keywords
 Identifiers
 Constants
 String
 Special Symbols
 Operators.

© Kalasalingam academy of research and education COURSE NAME


Information

Keywords:

⚫ Every C word is classified as either keyword or identifier.


⚫ All keywords have fixed meanings and you can not change its meanings.
⚫ Keywords serve as a basic building blocks for program statement. ANSI C supports 32 keywords.
⚫ Ex: int, float, double, extern, static, auto, continue, if, goto short, long etc. are the keywords

© Kalasalingam academy of research and education COURSE NAME


Information

Identifiers:

⚫ Identifiers refer to the names of variables, functions and arrays.


⚫ These are user defined names and consists of sequence of letters and digits.
⚫ Both uppercase and lowercase letters are permitted to make the identifier but generally lowercase
letters are used to make the variable.

© Kalasalingam academy of research and education COURSE NAME


Information

Rules for Identifiers:


⚫ Always the very first character of identifier is alphabet and underscore.
⚫ The blank/white space should not be given in between the identifier.
⚫ But underscore can be included anywhere in between the identifier.
⚫ Only first 31 characters are significant.
⚫ The keyword can’t be used as identifier.

© Kalasalingam academy of research and education COURSE NAME


Information

Constants:
⚫ Constants referred as a fixed value that don't change during the execution of the program.
⚫ C Support Several types of constants:
 Numeric Constants
Integer constants Real Constants

 Character Constants

Single Character Constants String Constants

© Kalasalingam academy of research and education COURSE NAME


Information

Integer Constants:
⚫ An integer constants refers as a sequence of digits.
⚫ There are three types of integer constants.
 Decimal Integer
 Octal Integer
 Hexadecimal

© Kalasalingam academy of research and education COURSE NAME


Information

Decimal Integer:

⚫ It consists of 0-9 digits, preceded by an optional – or + sign.


⚫ Valid example of decimal integer are : 123 , -321, 0 , 654321, +78
⚫ Embedded spaces, comma and non digit characters are not permitted between digits.
⚫ 15 750, 20,000, $1000 are Illegal

© Kalasalingam academy of research and education COURSE NAME


Information

Octal Integer:

⚫ An Octal Integers consists of digits 0-7 with a leading 0.


⚫ Example: 037, 0, 0435, 0551

© Kalasalingam academy of research and education COURSE NAME


Information

Hexadecimal Integer

⚫ A sequence of digits preceded by 0x or OX is considered as Hexadecimal Integer.


⚫ Hexadecimal Integer includes 0 to 9 digits and A to F letters.
⚫ Example: 0x9, 0x9F, OXBC etc are valid.

© Kalasalingam academy of research and education COURSE NAME


Information

Real Constants:

⚫ Integer numbers are inadequate to represent quantities such as distance, heights, temperature, price and
so on. These quantities are represented by a number containing fractional parts like 12.32. Such
numbers are called real constants
⚫ These numbers having a whole number followed by a decimal digits.
⚫ Example: 0.85, -0.75, 85.45, +241.54

© Kalasalingam academy of research and education COURSE NAME


Information

Real number:

⚫ A real number may also be expressed in exponential (Scientific) notation.


⚫ General form :mantissa e exponent
⚫ The mantissa is either a real number or integer number.
⚫ Exponent is an integer number with + or – sign.
⚫ The letter e separating mantissa and exponent can be written either in lowercase or in uppercase letter.

© Kalasalingam academy of research and education COURSE NAME


Information

Example :

⚫ 215.65 may be written as 2.1565e2 in exponential notation. e2 means multiple by 10^2


⚫ 75000 written as 7.5E4 or 7.5E+4
⚫ -0.00038 written as -3.8e-4
⚫ Comma, White space and dollar space is not permitted in digits.
⚫ 25,0.000 , 7.1 e 4 , 1.5 E 2.5 (exponent must be an integer),$255.

© Kalasalingam academy of research and education COURSE NAME


Information

Single Character Constants:

• A single character constant contains a single character enclosed with a pair of single quotation mark.
• Example: ‘1’, ‘a’, ‘$’

• Note that character constant ‘5’ is not same as number 5

• Character constant have a integer value known as ASCII value

© Kalasalingam academy of research and education COURSE NAME


Information

Example:

printf(“%d”,a); This will print the number stored in the variable ‘a’

printf(“%c”,97); This will print the character equivalent to the number 97 in ASCII

© Kalasalingam academy of research and education COURSE NAME


Information

String Constants:

⚫ A String Constant is a sequence of characters enclosed in double quotation mark.

⚫ Example:
⚫ “Hello” , “1987”, “Well Done”, “X”

⚫ Note : A single String constant does not have an equivalent integer value, while a character constant
has an equivalent integer value.

© Kalasalingam academy of research and education COURSE NAME


Information

Backslash Character Constant:

⚫ Backslash character constants are used in output function.

⚫ Example:
⚫ \n - new line,

⚫ \t - horizontal tab,

⚫ \v-vertical tab

© Kalasalingam academy of research and education COURSE NAME


Information

Variable:
⚫ A variable is a data name that may be used to store a data value.

⚫ Unlike constants that remain unchanged during the execution of the program, a variable may take
different value at different time.

© Kalasalingam academy of research and education COURSE NAME


Information

Rules to declare the variables


• It may start with alphabet or underscore(_)
• The integer number can be used after the first characters.
• It is case sensitive. It means, if we used the following variables like IT, it, It are different variable not a
same variable.
• The defined keywords can’t be used for the name of a variable.
• White space, Dollar sign can be avoided..

Example:
• Siva, Krishnankoil, BTech_first, char_type ---- valid
• Amt$, int, class first, 938, (volume) ------- Invalid

© Kalasalingam academy of research and education COURSE NAME


Information

Declaration of variables:
Syntax :
data_type v1,v2,v3….vn ;
where v1,v2..vn are different variable name.
Example:

• int count;

• int number, total;

• double ratio;

• float price;
• char c;
where int, double, float and char are data type.
© Kalasalingam academy of research and education COURSE NAME
Information

Assignment statement:

• Assignment operator (=) is used to assign value to a variable

Syntax:
variable-name = expression;
• Example:
price = 12.50;
number = 24;
character = ‘e’;
ratio = 12.2345;
a = a+2;
Note: Every statement must be ended with semicolon (;)
s = a+a*5;
© Kalasalingam academy of research and education COURSE NAME
Information

Assignment operator:
A value can be assigned to a variable when the variable is declared.
int radius = 10;
float pi = 3.14;
char f = ‘I’;
Several variable can be assigned the same using multiple assignment operators.
x=y=z=10;
f1=f2=‘I’; A same value can be assigned to multiple variables by
simply using assignment operators like this
speed=acce=0.0;

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Some operators used during the assignment statement like the following;
s = a+a*5;
Some other examples are These are operators
s= u*t + 1*f*t2/2; Operators

Arithmetic Relational Logical


operators operators operators

© Kalasalingam academy of research and education COURSE NAME


Information- operators

1. Arithmetic operators: These are normal addition and subtraction


operators

Addition : + This operator has to be used for multiplication


instead x used in school
Subtraction : -
Multiplication : * This operator has to be used for division
instead ÷ used in school
Division : /
Remainder or Modulus : % It is not a percentage sign. It means modulus
finding remainder:
For Example:
12 % 5 = 2
24 % 3 = 0

© Kalasalingam academy of research and education COURSE NAME


Information- operators

1. Arithmetic operators – examples:


distance = rate * time;
netIncome = income – tax;
speed = distance / time;
area = pi * radius * radius;
y = a * x * x + b * x + c;
quotient = dividend / divisor;
remain = dividend % divisor;

© Kalasalingam academy of research and education COURSE NAME


Information- operators

1. Arithmetic operators – examples:


Suppose x and y are two integer variables whose values are 20 and 6 respectively.

x+y 26 20
x–y 14
x*y 120 6
x/y 3
x%y 2 It returns the quotient only

It returns the remainder only

• In an expression, we may have different operator occurs.


• if more than one operator, how will that expression be evaluated based on their order?

© Kalasalingam academy of research and education COURSE NAME


Information- operators
Operator precedence:
The list in decreasing order of priority
S.No Operators Example Expression Priority Level
1 Parenthesis () x = (p + q) * z – x / (l + m); Highest Priority
2 Unary minus -8 x = 3; y = -4; z = x + y; Highest Priority
z = x + (-4); z = 3 – 4; z = -1;
3 Multiplicatio *, /, % -x / y * z % q; Same priority.
n, Division, left to right will
Modulus operate
4 Addition and +, - p+x*y/z–q Left to right
Subtraction

• For operators of the same priority, evaluation is from left to right as they appear.
• Parenthesis may be used to change the precedence of the operator evaluation.
© Kalasalingam academy of research and education COURSE NAME
Information- operators

Examples: Arithmetic expressions

a+b*c–d/e a + (b * c) – (d / e)
a*-b+d%e–f a * (-b) + (d % e) – f
a – b + c +d (((a-b)+c)+d)
x*y*z ((x * y) * z)
a+b+c*d*e (a + b) + ((c * d) * e)

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Integer Arithmetic:

• When the operands in an arithmetic expression are integers, the expression is called integer expression,
and the operation is called integer arithmetic.

• Integer arithmetic always yields integer values

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Real Arithmetic:
• Arithmetic operations involving only real or floating-point operands.

• Since floating point values are rounded to the number of significant digit permissible, the final value is
an approximation of the final result.
1.0 / 3.0 * 3.0 will have the value 0.99999 and not 1.0

• The modulus operator can not be used with real operands.


• 4.2 % 4 and 5.7 % 2.5 are not allowed.

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Mixed-mode Arithmetic:
when one of the operands is integer and the other is real, the expression is called a mixed-mode
arithmetic expression.
if either operand is of the real type, then only real arithmetic is performed, and result is a real number.
25 /10  2
25 / 10.0  2.5

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Problems of value assignment:


Assignment operation v = u means value is assigning to LHS
suppose
variable = expression_value; float u = 3.14;
int v;
or
v = u;
variable1 = variable2; then ‘v’ holds the value only ‘3’.
because float occupies 4 bytes in memory and int occupies
Data type of the RHS should be only 2 bytes
compatible with that if LHS

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Type casting:
Example 1:
int x;
float r = 3.0;
x = (int)(2*r);

Type casting of a floating point


expression to an integer variable

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Relational operators:
used to compare two values.
< is less than
> is greater than
<= is less than or equal to
>= is greater than or equal to
== is equal to
!= is not equal to

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Relational operators:
Examples:
10 > 20 is false
25 < 35.5 is true
12 > (7+5) is false
When arithemetic expressions are used on either side of a relational operator, the arithmetic expressions
will be evaluated first and then the results compared.
a+b>c–d is same as (a+b) > (c-d)

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Relational operators:
Examples:
Sample code segment in C x> N
y? print y is larger
if (x > y)
printf(“%d is larger\n”);
Y
else
printf(“%d is larger\n”) print x is larger

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Logical operators:
also known as logical connectives
They are
&&  Logical AND
||  Local OR
What they do?
• They act upon operands that are themselves logical expressions.
• the individual logical expressions get combined into more complex conditions that are true or false.

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Logical AND:
Temp > 50  (1)
a*b+c >= 25  (2)
These two are relational expressions
Connecting (1) and (2)
Temp > 50 && a*b+c>=25
Now, by connecting (1) and (2), we can make it to logical expressions

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Logical OR:
exp1 || exp2 || exp3
the whole expression will be if any one of expressions.
but none of them are true means, the whole expressions will be false.

© Kalasalingam academy of research and education COURSE NAME


Information- operators

Logical AND
Result is true if both the operands are true or if all operands are true.
Logical OR
Result is true if at least one of the operands are true.

X Y X && Y X || Y
FALSE FALSE FALSE FALSE
FALSE TRUE FALSE TRUE
TRUE FALSE FALSE TRUE
TRUE TRUE TRUE TRUE

© Kalasalingam academy of research and education COURSE NAME


Number system

Number System
Non-
Positional Decimal Binary Octal Hexadecim
positional
number number number number al number
number
system system system system system
system

© Kalasalingam academy of research and education COURSE NAME


Number System

Non-positional Number Systems


Characteristics
• Use symbols such as I for 1, II for 2, III for 3, IIII
for 4, IIIII for 5, etc
• Each symbol represents the same value regardless of its position in the number
• The symbols are simply added to find out the value
of a particular number
Difficulty
• It is difficult to perform arithmetic with such a number system

© Kalasalingam academy of research and education COURSE NAME


Number System

Positional Number Systems


Characteristics:
• Use only a few symbols called digits
• These symbols represent different values depending on the position they occupy in the number

© Kalasalingam academy of research and education COURSE NAME


Number System

Positional Number Systems


The value of each digit is determined by:
1. The digit itself
2. The position of the digit in the number
3. The base of the number system

(base = total number of digits in the number system)


The maximum value of a single digit is always equal to one less than the value of the
base

© Kalasalingam academy of research and education COURSE NAME


Number System

Decimal Number System


Characteristics:
• A positional number system
• Has 10 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Hence, its base = 10
• The maximum value of a single digit is 9 (one less than the value of the base)
• Each position of a digit represents a specific power of the base (10).

© Kalasalingam academy of research and education COURSE NAME


Number System

Decimal Number System

Example
258610 = (2 x 103) + (5 x 102) + (8 x 101) + (6 x 100)
= 2000 + 500 + 80 + 6

© Kalasalingam academy of research and education COURSE NAME


Number System

Binary Number System


Characteristics:
• A positional number system
• Has only 2 symbols or digits (0 and 1). Hence its base = 2
• The maximum value of a single digit is 1 (one less than the value of the base)
• Each position of a digit represents a specific power of the base (2)
• This number system is used in computers

© Kalasalingam academy of research and education COURSE NAME


Number System

Binary Number System

Example

101012 = (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) x (1 x 20)

= 16 + 0 + 4 + 0 + 1
= 2110

© Kalasalingam academy of research and education COURSE NAME


Number System

Representing Numbers in Different Number Systems

In order to be specific about which number system we are referring to, it is a common practice to
indicate the base as a subscript. Thus, we write:

101012 = 2110

© Kalasalingam academy of research and education COURSE NAME


Number System

Bit

• Bit stands for binary digit

• A bit in computer terminology means either a 0 or a 1

• A binary number consisting of n bits is called an n-bit number

© Kalasalingam academy of research and education COURSE NAME


Number System

Representation of various Memory Sizes

Name Equal To Size(In Bytes)


Bit 1 Bit 1/8

Nibble 4 Bits 1/2 (rare)

Byte 8 Bits 1

Kilobyte 1024 Bytes 1024

Megabyte 1, 024 Kilobytes 1, 048, 576

Gigabyte 1, 024 Megabytes 1, 073, 741, 824

© Kalasalingam academy of research and education COURSE NAME


Number System
Decimal Number Vs Binary Number Vs Hexadecimal Number

Decimal Binar Hexadecimal Decimal Binar Hexadecimal


y y
0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F
© Kalasalingam academy of research and education COURSE NAME
Data Encoding

• Base 64 is an encoding scheme that converts binary data into text format
• So that encoded textual data can be easily transported over network un-corrupted and without any data
loss.
• Base64 is used commonly in a number of applications including email via MIME, and storing complex
data in XML.
• Problem with sending normal binary data to a network is that bits can be misinterpreted by
underlying protocols, produce incorrect data at receiving node and that is why we use this code.

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

Why base 64 ?
• Resultant text after encoding our data has those characters which are widely present in many character
sets.
• so there is very less chance of data being corrupted or modified.

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

How to convert into base 64 format ?


The character set in base64 is

char_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
// 64 characters

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

ASCII Table

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

Example.
• We have to encode string “MENON” into base64 format.
• Lets call “MENON” as input_str, above base64 character set (“ABC..+/”) as char_set and resultant
encoded string as res_str.

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

Basic Idea:

Step 1: Take 3 characters from input_str i.e “MEN” since each character size is 8 bits we will have(8 * 3)
24 bits with us.
Step 2: Group them in a block of 6 bits each (24 / 6 = 4 blocks). (why 6?) because 2^6 = 64 characters, with
6 bits we can represent each character in char_set.
Step 3: Convert each block of 6 bits to its corresponding decimal value. Decimal value obtained is the
index of resultant encoded character in char_set.
Step 4: So for each 3 characters from input_str we will receive 4 characters in res_str.

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

Step 5:
What if we have less than 3 characters in input_str left i.e “ON”. We have 16 bits and blocks will be 16 /
6 = 2 blocks. Rightmost 4 bits will not make a proper block (1 block = 6 bits) so we append zeros to right
side of block to make it a proper block i.e 2 zeros will be appended to right. Now we have 3 proper blocks,
find corresponding decimal value of each block to get index.
Step 6:
Since There were less than 3 characters (“ON”) in input_str we will append “=” in res_str. e.g “ON” here
3 – 2 = 1 padding of “=” in res_str.

© Kalasalingam academy of research and education COURSE NAME


Data Encoding
Example 1:
• Convert “MENON” into its (8 bit) binary state format.
• Take each characters of the string and write its 8 – bit binary representation.
• ASCII values of characters in string to be encoded

M : 77 (01001101), E : 69 (01000101),

N : 78 (01001110), O : 79 (01001111), N : 78 (01001110)

resultant binary data of above string is :

01001101 01000101 01001110 01001111 01001110

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

Example 2:
Starting from left make blocks of 6 bits until all bits are covered
BIT-STREAM :
(010011) (010100) (010101) (001110) (010011) (110100) (1110)
Example 3:
If the rightmost block is less than 6 bits just append zeros to the right of that block to make it 6 bits. Here in
above example we have to appended 2 zeros to make it 6.
BIT-STREAM :
(010011) (010100) (010101) (001110) (010011) (110100) (111000)

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

Example 4:
Take 3 characters from input_str (“MEN”) i.e 24 bits and find corresponding decimal value (index to
char_set).
BLOCKS :
INDEX --> (010011) : 19, (010100) : 20, (010101) : 21, (001110) : 14
char_set[19] = T, char_set[20] = U, char_set[21] = V, char_set[14] = O

So our input_str = “MEN” will be converted to encoded string “TUVO”.

© Kalasalingam academy of research and education COURSE NAME


Data Encoding

Example 5:
Take remaining characters (“ON”). We have to pad resultant encoded string with 1 “=” as number of
characters is less than 3 in input_str. (3 – 2 = 1 padding)
BLOCKS :
INDEX --> (010011) : 19 (110100) : 52 (111000) : 56
char_set[19] = T char_set[52] = 0 char_set[21] = 4
So our input_str = "ON" will be converted to encoded string "T04=“.
Examples:
Input : MENON // string in ASCII
Output :TUVOT04= // encoded string in Base 64.

© Kalasalingam academy of research and education COURSE NAME


Functions
Information/Value/Data

Types of Information/Data
Different examples and their rules

Week 4 Summary
We learned about how to use the information/data
and convert into the corresponding types of data

© Kalasalingam academy of research and education COURSE NAME


Thank You!
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere,
magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.
© Kalasalingam academy of research and education COURSE NAME

You might also like