The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Checksum

1 reply on 1 page. Most recent reply: Mar 15, 2018 11:56 PM by jinf Fei

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Fuad Efendi

Posts: 1
Nickname: 102910
Registered: Jan, 2017

Checksum Posted: Jan 16, 2017 8:35 AM
Reply to this message Reply
Advertisement
Page 102 of the book (PDF, 3rd edition):

class ChecksumAccumulator {
  private var sum = 0
  def add(b: Byte): Unit = {
    sum += b
  }
  def checksum(): Int = {
    return ~(sum & 0xFF) + 1
  }
}


Why is such definition? I believe "checksum" is sum of Words in case of multi-Word representation in computer memory.

Can anyone confirm / explain method above, what it does and why it is called "checksum"? Thanks,


jinf Fei

Posts: 3
Nickname: jm8371
Registered: Mar, 2018

Re: Checksum Posted: Mar 15, 2018 11:56 PM
Reply to this message Reply
I think that it is a example to explain "singleton object"

Flat View: This topic has 1 reply on 1 page
Topic: Functional Queues | 3rd edition | listing 19.1 and 19.10 Previous Topic   Next Topic Topic: Understanding 'var' and 'val'

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use