Language: C
Write a function unsigned char tvect(unsigned char v) that accepts an unsigned byte value and returns a transitioned byte with the following properties.
• bit7 = bit2 XOR bit3 /* That is, bit7 in the return byte is equal to bit2 in v xor’d with bit3 in v */
bit6
bit5
bit4
bit3
bit2 bit7
bit1
bit0
= bit0
= bit1 OR bit2
= bit4 AND bit7 AND (NOT bit0)
= NOT bit5
= bit0 XOR bit1 XOR bit2 XOR bit3 XOR bit4 XOR bit5 XOR bit6
XOR
= bit1 AND bit2 = bit5 OR bit6
The question formatting is illegible so I am assuming this is the question asked.
bit6 = bit0
bit5 = bit1 OR bit2
bit4 = bit4 AND bit7 AND (NOT bit0)
bit3 = NOT bit5
bit2 = bit0 XOR bit1 XOR bit2 XOR bit3 XOR bit4 XOR bit5 XOR bit6 XOR bit7
bit1 = bit1 AND bit2
bit0 = bit5 OR bit6
Program:
unsigned char pow2[8] = {1, 2, 4, 8, 16, 32, 64, 128}; //storing powers of 2
int ISSET(unsigned char v, int i) //the ith bit can be extracted
by v AND 2^i i.e. v & pow2[i]
{
return (v & pow2[i]) != 0;
}
void SET(unsigned char *v, int i) //ith bit can be set by v OR
2^i i.e. v | pow2[i]
{
*v = *v | pow2[i];
}
unsigned char tvect(unsigned char v)
{
unsigned char ret = 0;
if(ISSET(v, 2) ^ ISSET(v, 3)) //condtion for 7th
bit
SET(&ret, 7);
if(ISSET(v, 0)) //condtion for 6th bit
SET(&ret, 6);
if(ISSET(v, 1) || ISSET(v, 2)) //condtion for
5th bit
SET(&ret, 5);
if(ISSET(v, 4) && ISSET(v, 7) &&
!ISSET(v, 0)) //condtion for 4th bit
SET(&ret, 4);
if(!ISSET(v, 5)) //condtion for 3rd bit
SET(&ret, 3);
//condtion for 2nd bit
if(ISSET(v, 0) ^ ISSET(v, 1) ^ ISSET(v, 2) ^
ISSET(v, 3) ^ ISSET(v, 4) ^ ISSET(v, 5) ^ ISSET(v, 6) ^ ISSET(v,
7))
SET(&ret, 2);
if(ISSET(v, 1) && ISSET(v, 2))
//condtion for 1st bit
SET(&ret, 1);
if(ISSET(v, 5) || ISSET(v, 6)) //condtion for
0th bit
SET(&ret, 0);
return ret;
}
Language: C Write a function unsigned char tvect(unsigned char v) that accepts an unsigned byte value...
You are writing code to control 8 stage lights in the Performing Arts Center. You start by accessing an 8-bit unsigned char value through a pointer called register. This value is used to turn lights on (1) and off (0). The diagram below is the bit map of a sample value for the stage lights, but the actual value will differ. bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 0 1 1 0 1 0 0 1 Your job is...
Compile the following C code into PICmicro Assembly Language Unsigned char a, b, c a 16 b 64 c= a + b
Java Language
Write a complete method calculateCost that accepts two parameters: a char representing package code for photo orders and a char representing a code for extra add- ons. The method returns a double representing the amount of the photo order (base order package order and any add-ons). Compute the amount of the order given the following table of base package codes: $12 $24 $40 $70 Add-on cost for the following codes: $5 n $5 MEN $10 no additional cost
Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...
C programming lab: Description: In this lab you will write a program that will contain two functions, setlsbs() and getlsbs(). These functions will use bitwise operators to embed and extract "hidden" bits in a character array. Write a program to test your functions as follows: Obtain a random number seed from the command line of your program using command line arguments. Initialize an array p of 8 unsigned char with random numbers from 0 to 255 Initialize a separate unsigned...
Develop in C language the function whose prototype is described below. Please, send the entire code, including any variable defined before the function, for example. / ** @brief Read bit of memory position pointed to by p @param p Pointer to 32bit variable whose bit will be read @param bitn Bit position (0 to 31) to be read @return returns the state (0 or 1) of the memory location bit pointed to by p * / unsigned char ReadBit (unsigned...
Write in C language
5. [8] Write a function with prototype » void string_copy(const char source[], char destination[], int n); This function copies string source to string destination. Parameter n represents the size of array destination. If the latter array is not sufficiently large to hold the whole source string then only the prefix of the string which has room in the latter array should be copied. Note that after copying, the null character should also be included to mark...
4. Hashing and Hash Tables. You need to use the ASCII table in the last page for this question. Study the following hash functions for ASCII C strings that are at least 3-char long unsigned hash1(const char, unsigned unsigned vto]+01997 return (v % m); unsigned hash2Cconst char unsigned) unsigned v-o]k(2] 877 return 1 + (v % ( -1)); (a) Given that m-, 7, compute the hash values and fill the following table (3%) String k hash1k, ) hash2(k, 7) aph...
C++ clock.h /* Write a function get_hours that returns an int and accepts an int seconds_since_1970 parameter */ int get_hours(int seconds_since_1970); /* Write a function get_minutes that returns an int and accepts an int seconds_since_1970 parameter */ int get_minutes(int seconds_since_1970); /* Write a function get_seconds that returns an int and accepts an int seconds_since_1970 parameter */ int get_seconds(int seconds_since_1970); clock.cpp #include "clock.h" /* Write get_hours code to return hours given seconds since 1970 int */ /* Write get_minutes code to...
Write a MIPS assembly instruction that loads the value of a signed char (C++ char datatype uses 1 byte) variable in register $s1. The address of this variable is stored in register $s4.