Question

​​​​​​​Please write code in R Create two character vectors S11 and S12 such that S11 contains...

​​​​​​​Please write code in R

  1. Create two character vectors S11 and S12 such that S11 contains the binary representations of the numbers (5,2,1,6,3,4,7,0), and S12 contains those of the numbers (1,4,6,2,0,7,5,3). (10 points)
  2. Let b=”1101”. Extract the last three characters. Convert the last three characters into decimal and store it in a variable called tempVal. Write an “if-then-else” statement such that if b[1] == 0 retrieve the value of S11[tempval]. If b[1]==1 retrieve the value of S12[tempval] and store it in a variable tempRet. (Hint: You might need to shift the indices by 1) (10 points)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#R version 3.3.2

S11D<-c(5,2,1,6,3,4,7,0)
S12D<-c(1,4,6,2,0,7,5,3)

#convert to binary
S11<-c()
for (i in 1:length(S11D)) {
S11[i] <- paste(rev(as.integer(intToBits(S11D[i]))), collapse="")
}

#convert to binary
S12<-c()
for (i in 1:length(S12D)) {
S12[i] <- paste(rev(as.integer(intToBits(S12D[i]))), collapse="")
}
print("S11 Vector: ")
print(S11)
print("S12 Vector: ")
print(S12)


b<-"1101"
#last three characters of b
b1<-substr(b, nchar(b)-3+1, nchar(b));

#convert b1 to decimal
tempVal<-strtoi(b1, base = 2);

print("Accessing vector based on var b")
if(substring(b, 1, 1)=="0") {
tempRet<-S11[tempVal];tempRet
} else if(substring(b, 1, 1)=="1") {
tempRet<-S12[tempVal];tempRet
}

Please give thumbs up to solution.

Add a comment
Know the answer?
Add Answer to:
​​​​​​​Please write code in R Create two character vectors S11 and S12 such that S11 contains...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. DON'T use Function concept or any other concept except while loop,if-else. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not...

  • Write a C++ program which makes a binary tree that generates the Huffman code for any...

    Write a C++ program which makes a binary tree that generates the Huffman code for any 7 characters and their given frequencies. As test input use a 3, b 4, c 1, d 3, e 12, f 4, g 2. Your program must insert nodes, and output the code for each character. Note: your program should be able to take any 7 characters and their frequencies as input. Three extra points if your program can accept 26 letters and 10...

  • Use c-strings for the following project: Write a C++ program that declares an array containing up...

    Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...

  • Write in C++: Please create a shopping list using the STL list container, then follow the...

    Write in C++: Please create a shopping list using the STL list container, then follow the following instructions. Create an empty list. Append the items, "eggs," "milk," "sugar," "chocolate," and "flour" to the list. Print the list. Remove the first element from the list. Print the list. Insert the item, "coffee" at the beginning of the list. Print the list. Find the item, "sugar" and replace it with "honey." Print the list. Insert the item, "baking powder" before "milk" in...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • Please help solving these following questions: Convert 18210 into binary (or into hex). Convert 3276810 into...

    Please help solving these following questions: Convert 18210 into binary (or into hex). Convert 3276810 into binary (or into hex). Convert E7A216 into binary or decimal. Convert 11100101102 into decimal (or into hex). • Understand or code a function that uses default parameters. • Describe or use a group of overloaded functions.• Write a function to find the average of a 1-dim array of floats. • Write a function to multiply two 1-dim arrays together to produce a third array...

  • 1. (2 pts) Perform a multiplication of two binary numbers (multiplicand 0101 and multiplier 0101) by...

    1. (2 pts) Perform a multiplication of two binary numbers (multiplicand 0101 and multiplier 0101) by creating a table to show steps taken, multiplicand register value, multiplier register value and product register value for each iteration by following the steps described in the following document. (Points will be deducted if steps are not shown.) Read this steps You can use this table to start: Multiplication table 2. (2 pts) Perform a division of two binary numbers (divide 0010 1101 by...

  • PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test...

    PLEASE HURRY Software Testing Don't make any changes to the provided code. Please write a test case for the below prompt using the provided java programs Use the setString() function in MyCustomStringInterface to set the value to “Peter Piper picked a peck of pickled peppers.”. Then test to see if reverseNCharacters() function returns the reversed string when the characters are reversed in groups of 4 and padding is disabled (in this case, “etePiP r repkcipa decep fo kcip delkpep srep.”)....

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT