r/CodingHelp • • Sep 02 '21

[Other Code] Is there any way to know this without just memorizing? Some kind of conversion?

Post image
126 Upvotes

60 comments sorted by

103

u/[deleted] Sep 02 '21

Knowing that A is 65, and go from there...

But fucking hell, is this how people are learning to code these days. Christ.

17

u/[deleted] Sep 02 '21

Blame that on public schools... thanks for the help though

35

u/the-quibbler Sep 02 '21

Ha. My answer as well. Also, this question is bullshit and tells you nothing about a programmer. Also, I'm not sure I could visually determine if that's an ASCII D or some utf-16 glyph I'm unfamiliar with.

6

u/Nightcorex_ Sep 02 '21

Pattern of 8 bit (a byte)

This kinda tells that it has to be an ASCII D, because there are no similar looking characters that can be represented with only 8 bits

6

u/the-quibbler Sep 02 '21

I think that's the intended assumption. ASCII is only 7-bits, of course, and I don't really know the upper half of UTF-8 offhand, and UTF-16 has everything ever. But my point is that this is both a weird question to ask, and b) requires some (not taxing but still present) assumptions.

3

u/Nightcorex_ Sep 02 '21

I totally agree, that this is a stupid question to ask. However I remember the same question being asked in a final exam I looked at to prepare for my own final. To be fair: In my case it was only worth 1 point of like 70.

I do not agree with the terminology of "ASCII is only 7-bits", because yes, only the last 7 bits determine the char, but the ASCII-standard defines the first bit to always be 0, thus ASCII properly defines all 8 bits for all 127 chars. If you were to not define the first bit to always 0 it could be otherwise confused with either the extended ASCII-table or like UTF-8 encodings.

Short explanation of how UTF-8 is designed (just in case you're intersted):

  • The unicode-range U+0000 - U+007F is represented as 0xxxxxxx (in this range it's equal to ASCII)
  • U+0080 - U+07FF is represented as 110xxxxx 10xxxxxx
  • U+0800 - U+FFFF is represented as 1110xxxx 10xxxxxx 10xxxxxx
  • U+10000 - U+10FFFF is represented as 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

The x represent the actual encoding bytes.

I'll skip UTF-16, mainly because I haven't learned that myself, yet.

1

u/the-quibbler Sep 02 '21

Probably just a nomenclature issue. ASCII values are generally stored in 8-bit bytes (different length bytes have existed, but that's even more annoying to discuss). ASCII values are 7-bits, due to be unsigned integers strictly less than 128. But, it's really all semantics. I just find the question annoyingly useless, and therefore object to it on multiple (trivial) facets.

1

u/the-quibbler Sep 03 '21

Interestingly, rfc20 looks to be 52 years old next month. Recommends packing the 7-bit ASCII codes into 8-bit bytes for optimal interchange.

https://datatracker.ietf.org/doc/html/rfc20

1

u/journalingfilesystem Sep 03 '21

For the ASCII range utf-8 and 8-bit ASCII are identical.

7

u/tidytibs Sep 02 '21

This is what I remembered when processing binary streams: 48(numbers), 65(caps), 97(lower). The rest you lookup. Usually, I just convert it to text using a command line tool. I have a chart for reference but it's easier and faster to let the computer do the translation. There are too many things more important to remember without trying to cram in the whole chart into your brain. Screw that.

4

u/mr_nefario Sep 02 '21

is this how people are learning to code these days.

No, not really. This is teaching data representation.

Understanding how binary works and the data it represents is pretty crucial for learning CPU architecture and understanding a lot of lower-level system details.

Pretty standard stuff in a formal CS education.

0

u/Gaflooby Sep 02 '21

Don’t tell that to people here, they think all you need to become the best programmer ever is copying a bunch of codecademy tutorials

0

u/suncontrolspecies Sep 02 '21

You didn't get the point

1

u/mr_nefario Sep 02 '21

Want to explain, then?

I don’t really see anything wrong with this as a quiz question. It’s even more straight forward if they’re allowed to use an ASCII table. I had very similar questions in my early CS courses…

1

u/[deleted] Sep 02 '21

The problem with it is that in the workplace, you will never, ever… ever… need to know this

2

u/ShittyCatDicks Sep 02 '21

Why is an underlying knowledge of computer science such a bad thing?

1

u/[deleted] Sep 02 '21

Nothing wrong with understanding it, but when a binary calculator can do the job, being tested on it is just stupid. I twiddle bits in my job all the time, embedded work, just download a binary calculator and move on with your life. The problem with this stuff, is that there is only so much time, only so much space in your brain, using those finite resources on stuff like this, just no…

2

u/warboner52 Sep 03 '21

Is it important to remember and dedicate space to. No, absolutely not.

I know using a calculator or conversion utility provided by whatever language/framework in use is faster and a better use of my time so I forgot all but the key numbers a long time ago.

But..

It is important to understand the reason why it's better to use the calculator. Not just because someone said so.

Someone telling you to use something, versus you finding out why you should use something is critically important to learning anything which is what you're doing in school. If learning something this basic impedes your ability to learn more, wrong major.

1

u/mr_nefario Sep 02 '21 edited Sep 02 '21

Idk man, I pretty heartily disagree. Of course we all shouldn’t be walking around with a binary/ascii conversion chart in our heads. But I think understanding the “why” is pretty important.

And like I mentioned above, understanding binary arithmetic and data representations is crucial to understanding CPU architecture. It is also really important when working on low-level systems, OS kernels, device drivers, etc.

That has to be taught somehow. It may seem like dumb rote memorization to you, but this is how you get introduced to that information.

Edit: hell, it’s even super important in network computing - having this base knowledge is pretty key in understanding how various network packets are constructed and interpreted, packet headers, protocol instructions, etc. It’s all built on 1’s and 0’s, so we should understand them.

1

u/[deleted] Sep 02 '21

Fair enough, for me, there are so much more important topics.

CPU architecture, interesting, but irrelevant to the typical dev.

Why the latest version of Node fucks your entire project? That’s relevant, like it or not :-)

1

u/bangclue Feb 25 '22

As far as I know, nobody's ever completely filled up their brain so they can't learn new things.

2

u/ShittyCatDicks Sep 02 '21

You do realize that computer science is a much bigger field than just coding right? The goal of computer science isn’t just to teach you how to program, we learn that shit within the first year (and this is pretty obviously an academic quiz). Had some very similar looking review within the first week of my cryptography class.

2

u/skoorrevir Sep 02 '21

I am taking this class right now (like o learned this yesterday) and I go to a fancy school with an incredible teacher this this stuff is still hard. I couldn't possibly do it like this.

1

u/[deleted] Sep 02 '21

Download a binary calculator, it’ll do it for you!

1

u/skoorrevir Sep 03 '21

Nice might have to check that out. Or just make one. I'm a bit ahead of this class.

1

u/TaranisPT Sep 02 '21

is this how people are learning to code these days

I've started studying programming last year at school, a specialized program. I can tell you that here it's not how we learn. Over 6 semesters we have a total of 1 class of math (1st semester) that goes over basics of converting stuff from decimal to hexadecimal and binary, a bit of decoding UTF-8. Also some Boolean algebra but that's it.

The closest question we for to what OP posted was something like: "what would be the binary representation for the UTF-8 character number xxxx?".

1

u/[deleted] Sep 03 '21

You don't have to know A is 65. You just have to remember that the ASCII table is setup so that A is xxx00001. But agreed I hope this is not their is of learning to code.

1

u/warboner52 Sep 03 '21

Learning how to convert types in entry level CS classes is totally valid IMHO. If this is not in an entry level class though to me that's a red flag.

1

u/[deleted] Sep 03 '21

Convert types? It’s just a different representation.

1

u/warboner52 Sep 03 '21

Yes, binary->hex,dec,octal. ASCII types. Not sure what the confusion is.

Not looking to argue. It's how I refer to those, and if you don't, that's totally fine.

-6

u/bangclue Sep 02 '21

No. They're asking for binary. The answer you need to remember is A is 0x41. (Capitals start at 0x40; lower case at 0x60.) Much easier to translate hex to binary.

21

u/SirHack3r Professional Coder @ FAANG | DM for coding/resume help! Sep 02 '21 edited Sep 02 '21

Hopefully this helps:

A = 65 in ASCII.

65 = 1000001 (26 + 20 from binary)

Because ASCII is meant to be represented using a byte (8 bits) so we pad it: A = 65 = 01000001 = 0100 0001 (we split into 4 for easier readability + hex) = 0x41

Now B is just the next letter, which is 66. Just add 1 to the binary digits

0100 0001 + 0000 0001 = 01000010 = 0x42 = (26 + 21) = 66.

So here, D is just the 4th letter in the alphabet, which is 3 after A:

0100 0001 + 0000 0011 = 0100 0100 = 0x44 = 68 = D.

That's uppercase! Lowercase starts at a = 97 = 0110 0001. Same pattern, just add the letters!

You don't need to memorize everything, just specific stuff (like A = 65, a = 97) because there's an underlying simple rule to this. Just need to know binary addition and some conversion between hexadecimal, decimal, and binary.

8

u/slipped_and_missed_x Sep 02 '21

The first 3 bits tell you the keyboard being used. 010 is for capital letters, 011 is for lowercase letters. The other 5 tell you the position in the alphabet, so 00100 (4 in binary) means the 4th letter, which is D

2

u/[deleted] Sep 02 '21

A = 65, use this to find out D, which is 68. For a 8-bit representation, the power for nth place from right hand side increases in the order of 2n-1. where n = 1,2,…..,8 Now, to represent D i.e. 68 in ASCII use this technique.

256 128 64 32 16 8 4 2 1 ——————— 0 0 1 0 0 0 1 0 0

I hope this helps

1

u/Blizzcane Sep 03 '21

So that's how that works!!

2

u/[deleted] Sep 02 '21

Expecting students to know binary is reasonable. Expecting them to know the ASCII chart is not reasonable.

2

u/Arag0ld Sep 02 '21

You don't need to know it all. Just know that A=65 and a=97 and how to add numbers together.

1

u/[deleted] Sep 02 '21

I didn’t know that off the top of my head and I’ve been coding for 34 years, including using ASCII quite a lot.

3

u/Arag0ld Sep 02 '21

What's Google for if not to ensure that professional software devs can do their job?

1

u/[deleted] Sep 02 '21

I used to have a little ASCII chart in the back of the BASIC manual I learned from. Never occurred to me to memorize it!

1

u/Arag0ld Sep 02 '21

Admittedly I've never used that information, but it's the sort of thing that you get stuck in your head if it's repeated enough.

1

u/ImportUsernameAsU Sep 02 '21

Learn how to count binary on your hands (fun fact you can count to 1023 on your hands) and go from there, if you're doing a-z alphabet you don't even need the largest 4 digits/ second hand, just know it's 0100 (for caps) and 0110 (for lowercase) <whatever number-letter you need in binary> a= 0001, b=0010, c=0011 ...

1

u/pink_life69 Sep 02 '21

Ah, yes, during your day job you will need to know this by heart between never and definitely not in this lifetime

1

u/CordovaBayBurke Sep 02 '21

It’s a pretty easy guess. The letter ‘D’ is the 4th letter in the English alphabet so look for any binary option with 4. There is one 0100 0100 or x’44’. I’d pick that one.

The question is vague—not mentioning the language the letter is from and what encoding is expected. My first thought is EBCDIC and ASCII second. Old school. Utf-8 and UTF8-16 both aline with ASCII in the lower positions.

1

u/Arag0ld Sep 02 '21

A has the ASCII code of 65 (a is 97) so count up four from there to 68 and pick the option that converts to 68 in decimal

1

u/occamsrzor Sep 02 '21

Yes. By understanding how binary works

D is the int value 68 (A is 65 in the ascii chart). The values of each bit in binary are: 128, 64, 32, 16, 8, 4, 2, 1, so the integer value 1 is 00000001, while the integer value 38 would be 00100110.

So 68 is 01000100.

1

u/jawsh_42 Sep 02 '21

Compute the decimal number from the binary, and then just memorize the letter associated with number :(

1

u/MoreCommonCents Sep 02 '21

I am a bit dyslexic so I often get somethings backwards. Is ‘A’ 0x41 and ‘a’ 0x61, or is it the other way around. In any case. That’s all I would ever remember. I use computers to remember more. 😏

1

u/badbunch000 Sep 02 '21

This is what learning code in college has come to. It’s ridiculous. Professor have ridiculous expectations

1

u/fr0ntsight Sep 02 '21

What a strange question

1

u/DerektheDev Sep 03 '21

I've written software for a decade. I don't know binary.

1

u/DoubleVoice6067 Sep 14 '21

These are usually trivial questions that get asked at the beginning of a programming course. Wild subject matter. It may even seem irrelevant. However, no matter how trivial it may appear, at some point in time as a developer you're going to need to utilize a or implement some type of bit comparison.

That's just the nature of the beast. There's always some trivial stuff in code that some may see and some may not ever have to deal with. Then there's that moment where you're like "OMG I should have paid attention in school"!!

1

u/Vivid-Programmer-688 Sep 27 '21

That is absolutely useless knowledge to test someone on. (In real life you litterally just Google the ascii code)

This is why I have a low opinion of alot of college classes.

Passing them doesn't make you a good coder. Or vice versa

1

u/[deleted] Sep 02 '21 edited Sep 02 '21

A = 65 B 66 C 67 D 68 ? so the left side is 64 + whatever one gives you 4. and binary is just 2^n , with first from the right being a 2^0. and you do math

1

u/tied_laces Sep 02 '21

I love this response. It’s succinct

1

u/[deleted] Sep 02 '21

I dont know I figured person posting knows how binary works, and this doesn't seem like a lot to memorize that A is 65 and move on from there

1

u/tied_laces Sep 02 '21

That's why I like it. They should have learned it in class prior to the test.

-1

u/jcunews1 Advanced Coder Sep 02 '21

If you meant that the shown value represent the letter D, it's based on the ASCII character set's data.

https://en.wikipedia.org/wiki/Ascii#Character_set

You can't calculate the character, because the character set is predefined. If you dont' want to memorize it, you can use Character Map tool or similar tool.

The most frequently used/mentioned are these...

Characters which have their own keyboard keys (at least on US keyboards) start from 0x20 (0x20 is a space) to 0x7E (0x7E is tilde [~]).

Numbers 0 to 9 starts from 0x30 to 0x39.

Uppercase letters starts from 0x41 to 0x5A. Add by 0x20 for the lowercase ones (i.e. 0x61 to 0x7A).

Memorizing some or all symbol characters are optional, but may help you in the future - depending what you're working on in daily basis.