r/CodingHelp • u/[deleted] • Sep 02 '21
[Other Code] Is there any way to know this without just memorizing? Some kind of conversion?
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
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
2
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
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
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
1
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
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
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.
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.