#Help me understand

37 messages · Page 1 of 1 (latest)

cerulean yoke
inland cypressBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

grizzled lynx
#

!hw

inland cypressBOT
# grizzled lynx !hw
Zelis, Herald of Krill Issues
We Don't Do Your Homework

Welcome to Together C & C++ :wave:

We won't do your homework for you (#rules) but we are happy to help you learn and point you in the right direction.

Please send what you have so far and ask a specific question.

grizzled lynx
#

!howto ask

inland cypressBOT
# grizzled lynx !howto ask
How to Ask a Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What to Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error)
    :trophy: Gold Standard: Minimal Reproducible Example
Where to Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C and C++ snippets
  • OnlineGDB for interaction, debugging
    :no_entry: Do not post screenshots, let alone photos of your screen!
coral ocean
#

fuck, beat me to it 😅

#

But... Why would you want to use C for that?

cerulean yoke
#

how do i convert a string of characters to binary in c? for example: aaa, into a long binary

coral ocean
#

There are certainly easier options like Python which they also allow you to use

cerulean yoke
#

idk how to code in python

#

my assignment is to calculate the check sum for a string of characters in 8bit, 16bit, and 32bit checksum bit size

#

however i’m stuck on how to actually convert the string of characters into binary

coral ocean
#

I mean, each of the characters of a string is just a number already

#

like e.g. 'a' is 97 and '\n' is 10

cerulean yoke
#

i tried adding just the ascii values of each character and then converting it into hexadecimal, however it was wrong. we have to add them through their binary numbers and ignore and overflow

coral ocean
#

Can you draw out what you want to happen on paper? I.e. could you calculate the checksum for a small string by hand?

cerulean yoke
coral ocean
#

That's for the 8-bit checksum, no?

cerulean yoke
#

yes that is

coral ocean
#

Okay, that's the easy one, you just add each character to a uint8_t sum variable and that's your checksum.

How about for the 16-bit checksum? Can you do that on paper for the string "abc\n"?

cerulean yoke
coral ocean
#

The computer only sees a number, and the translation from and to a character is purely for us humans

#

and we have defined the ASCII table to standardize which number should translate to which character (and vice versa)

cerulean yoke
#

so if i were to add the character it would add its binary?

coral ocean
#

yes

#

The computer only knows binary numbers.
Just like with the translation from numbers to characters (and the other way around), the computer also translates all the binary numbers into decimal ones again purely because us humans suck at reading binary

cerulean yoke
#

then how would i ensure that it doesn’t take in the overflow, and instead cuts it off

coral ocean
#

wdym? "Doesn't take in the overflow"

cerulean yoke
#

in the example i showed in the picture, i didn’t count into the sum the 1 that carries over

coral ocean
#

well, how would you?

cerulean yoke
#

that’s the issue i’m having ;-;

coral ocean
#

I mean. That should be your main issue

#

Also your assignment from time to time references your lecture and expects some knowledge of your lecture to properly understand how they want the checksum to be implemented

river whale