Bytes

Task 1

Write a function called IsValidByte which takes a string as its argument and returns TRUE if the string has exactly 8 characters which are all “0” or “1”. For example:

  • IsValidByte(“01101010”) should return TRUE
  • IsValidByte(“1101010”) and IsValidByte(“01201101”) should both return FALSE.

Task 2

Write a function called AddBytes which takes two valid strings representing bytes as its arguments and returns a string which represents the sum of the two bytes using Binary arithmetic. For example:

  • AddBytes(“10010100”, “01001101”) should return “11100001”
  • Note that you are NOT ALLOWED to convert these strings to their equivalent integers!

Extension: How does your function cope with overflow?).

About CDB 361 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.