multiplying to bye arrays

This is a discussion on multiplying to bye arrays within the C Programming forums, part of the General Programming Boards category; Hi all, I am trying to write a C code to multiply 2 byte arrays and then divide the answer ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    8

    multiplying to bye arrays

    Hi all,
    I am trying to write a C code to multiply 2 byte arrays and then divide the answer by 200 . any ideas how to do that ?
    thank you

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That depends entirely what you mean by "multiplying two byte arrays". Multiplying one byte by one byte? Multiplying two-bytes-at-a-time by two-bytes-at-a-time? What about overflow?

    In any event, some sort of loop seems indicated.

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    8
    thank you very much ... the two arrays are the same , i just need to square one and then divide the answer by 200

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by john27 View Post
    thank you very much ... the two arrays are the same , i just need to square one and then divide the answer by 200
    So then that's what you do. Go through every element of the array, multiply the element by itself and divide by 200.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,046
    You should probably cast to int before multiplying. Otherwise you risk overflow even when your result is less than the max value of a byte.
    Last edited by King Mir; 07-12-2011 at 04:36 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    Are the array's elements independent of each other?

    Yes => Do what @tabstop told you.

    No => Forget it! Use an arbitrary-sized arithmetics library instead.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble multiplying these arrays...
    By UCFuser in forum C Programming
    Replies: 3
    Last Post: 03-30-2011, 01:12 PM
  2. Multiplying Huge numbers in integer arrays
    By invierno in forum C Programming
    Replies: 5
    Last Post: 04-11-2009, 08:40 PM
  3. Multiplying arrays (dot vectors)
    By Matter711 in forum C Programming
    Replies: 3
    Last Post: 05-09-2008, 09:30 PM
  4. question on multiplying 2D arrays
    By 3kgt in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2003, 08:26 PM
  5. Multiplying! PLEASE HELP!!!!!!!!!!!!!
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 10-23-2001, 09:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21