Alp Worksheet
Alp Worksheet
1. Create a menu driven program to accept a decimal number as input and convert it into equivalent
binary, octal and Hexadecimal
2. Implement the following logical operations using C/C++ language. The inputs and the observed
output should be a string of binary digits.
AND, OR, XOR, NAND
3. Implement the following Shift /Rotate operations using C/C++ language.( Use Functions)
SHIFT LEFT, SHIFT RIGHT by specified no. of positions.
Circular Shift (ROTATE) by specified no. of positions.
4. Write a function that prints a negative number in the following formats:
Signed magnitude data representation
One’s complement integer data representation
Two’s complement integer data representation
5. Perform the following arithmetic operations using 2’s Complement notation: Take two 8 bit binary
numbers( MSB as sign bit) as input A and B
(+A) + ( +B),
(+A) + ( -B)
(-A) + ( +B)
(-A) + ( -B )
(+A) - ( +B)
(+A) - ( -B)
(-A) - ( +B)
(-A) - ( -B )
6. Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the
rightmost n bits of an unsigned char variable y (leaving other bits unchanged).
e.g. if x = 10101010 (170 decimal) and y = 10100111 (167 decimal) and n = 3 and p = 6 say then
you need to remove off 3 bits of y (111) and put them in x at position 10xxx010 to get answer
10111010.
Your answer should print out the result in binary form although input can be in decimal form. Your
output should be as follows:
x = 10101010 (binary)
y = 10100111 (binary)
setbits n = 3, p = 6 gives x = 10111010 (binary)
7. Write a program last that prints the last n lines of its text input. By default n should be 5, but your
program should allow an optional argument so that
last -n
prints out the last n lines, where n is any integer. Your program should make the best use of available
storage. (Input of text could be by reading a file specified from the command or reading a file from
standard input)
8. Write a C program to produce a series of floating point random numbers in the ranges (a) 0.0 - 1.0
(b) 0.0 - n where n is any floating point value. The seed should be set so that a unique sequence is
guaranteed.