Hello, I have some problems with this code. It says: "Main.scala:1: error: expected class or object definition def extend(p: Long): Long = { ^ Main.scala:21: error: expected class or object definition def ok(x: Long): Boolean = { ^ 2 errors Could you please help me fix it? Code: def extend(p: Long): Long = {   // Count the number of 1's in the payload   var count = 0   for (i <- 0 until 63) {       if ((p & (1L << i)) != 0) {           count += 1       }   }   // Set the parity bit to 0 or 1 depending on whether the number of 1's is even or odd   if (count % 2 == 0) {       p | (1L << 63)   } else {       p & ~(1L << 63)   } }     def ok(x: Long): Boolean = {   // Count the number of 1's in the extended payload   var count = 0   for (i <- 0 until 64) {       if ((x & (1L << i)) != 0) {           count += 1       }   }   // Return true if the number of 1's is even and false if it is odd   count % 2 == 0 }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hello, I have some problems with this code.

It says:

"Main.scala:1: error: expected class or object definition
def extend(p: Long): Long = {
^
Main.scala:21: error: expected class or object definition
def ok(x: Long): Boolean = {
^
2 errors

Could you please help me fix it?

Code:

def extend(p: Long): Long = {
  // Count the number of 1's in the payload
  var count = 0
  for (i <- 0 until 63) {
      if ((p & (1L << i)) != 0) {
          count += 1
      }
  }
  // Set the parity bit to 0 or 1 depending on whether the number of 1's is even or odd
  if (count % 2 == 0) {
      p | (1L << 63)
  } else {
      p & ~(1L << 63)
  }
}

 

 

def ok(x: Long): Boolean = {
  // Count the number of 1's in the extended payload
  var count = 0
  for (i <- 0 until 64) {
      if ((x & (1L << i)) != 0) {
          count += 1
      }
  }
  // Return true if the number of 1's is even and false if it is odd
  count % 2 == 0
}

1 def extend (p: Long): Long = {
2 // Count the number of 1's in the payload
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var count = 0
for (i < 0 until 63) {
if ((p & (1L << 1)) != 0) {
count += 1
}
// Set the parity bit to 0 or 1 depending on whether the number of 1's is even or odd
if (count % 2 == 0) {
p (1L << 63)
} else {
}
p & (1L << 63)
20
21 def ok (x: Long): Boolean = {
22
23
24
25
26
27
// Count the number of 1's in the extended payload
var count = 0
for (i <-0 until 64) {
if ((x & (1L << i)) != 0) {
count += 1
Main.scala:1: error: expected class or object definition
def extend(p: Long): Long = {
A
Main.scala:21: error: expected class or object definition
def ok(x: Long): Boolean = {
A
2 errors
Transcribed Image Text:1 def extend (p: Long): Long = { 2 // Count the number of 1's in the payload 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 var count = 0 for (i < 0 until 63) { if ((p & (1L << 1)) != 0) { count += 1 } // Set the parity bit to 0 or 1 depending on whether the number of 1's is even or odd if (count % 2 == 0) { p (1L << 63) } else { } p & (1L << 63) 20 21 def ok (x: Long): Boolean = { 22 23 24 25 26 27 // Count the number of 1's in the extended payload var count = 0 for (i <-0 until 64) { if ((x & (1L << i)) != 0) { count += 1 Main.scala:1: error: expected class or object definition def extend(p: Long): Long = { A Main.scala:21: error: expected class or object definition def ok(x: Long): Boolean = { A 2 errors
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY