Assignment 2 C programming with bit-manipulation Solution

$24.99 $18.99

In this assignment we will learn how to inspect and modify individual bits in memory. Remember that everything in computers is represented by just a series of 0’s and 1’s. This means that the software has to remember how each part of memory is converted from 0’s and 1’s to something else. Here’s a simple…

Rate this product

You’ll get a: zip file solution

 

Categorys:

Description

Rate this product

In this assignment we will learn how to inspect and modify individual bits in memory. Remember that everything in computers is represented by just a series of 0’s and 1’s. This means that the software has to remember how each part of memory is converted from 0’s and 1’s to something else. Here’s a simple example: Suppose the memory location 0xAFF5C3 (that’s a hex number, don’t worry about it now) contains

0xAFF5C3

2.1.1 More Bit Manipulation

Write the function bit check(int data, int bits on, int bits off), to check an int to see if a specific set of bits (aka a “bit mask”, call it bits on) is set AND that another set of bits (bits off) is clear. Returns 1 if the int called data matches the bit masks, and 0 if not.

However, note there is a special case. For example, suppose I write int data = 0xFF;

bit_check(data, 0x32, 0x20);

There’s a problem! Because 0x32 & 0x20 = 0x20 , we are asking that bit 0x20 must be BOTH off and on! Your function should return -1 for any case of testing that any bit is BOTH off and on.

2.2 Basic Pointer Declaration and use

In this part we will use pointers to designate capitol letters of the alphabet which are put into memory through the pre-defined array a array[].

Write a function pmatch() which will take a character and return a pointer to the element in a array[] which matches it. If there is no such character (e.g. pmatch(’m’)), then return the NULL pointer.

2.3 Pointer Arithmetic

nlet(C)

You can meaningfully do certain kinds of math with pointers (but e.g. x = sqrt(ptr) is meaningless). Here you should write a function to give the next letter in the alphabet in response to a pointer into the alphabet array. If the pointer points to ’Z’, there is no next letter so return -1. if the pointer does not point to an element of the array, also return -1.

ldiff(C1,C2)

Find the number of characters between two letters of the alphabet using pointer arithmetic. Include C2 in the count but not C1. For example ldiff(’A’,’E’) == 4 is true and ldiff(’E’,’A’) == -4 is true. Check for errors. If either letter is not a capital letter, return a negative number less than 26.

2.4 Structs and sizeof

You might have used classes in a previous programming course/language. In C we don’t have classes but structs are basically like a class with no methods.

Here you are going to set up a struct to represent some data about people, and a couple of functions which work with pointers to those structs. Specifications for the struct are:

/*

  • Define a typedef struct called Person containing:

  • 1) 20 char string: FirstName

  • 2) 30 char string: LastName

  • 3) 80 char string: StreetAddr

  • 4) 6 char string: ZipCode

  • 5) double: Height // height in meters

  • 6) float: Weight // weight in kg

  • 7) long int: DBirth // birthday (days since 1-Jan-1900)

  • /

A sample of the struct definition is in functions.h, modify this to the above specifications.

Your function print person() must accept a pointer to a Person struct, and neatly print out all data (see sample output). The street address can store 80 characters (see above) but the printout should be limited to 60 characters. See comments for additional instructions of functions to write.

Assignment 2 C programming with bit-manipulation Solution
$24.99 $18.99