Integer Bases Exercises
p1 (base conversions)
Complete the following table by hand. For binary, write 8 digits, padding with leading zeroes if necessary. Note that the underscore is there purely for readability.
| Decimal | Binary | Hexadecimal |
|---|---|---|
| 1 | ||
| 21 | ||
| 0b1000_0001 | ||
| 0x1e |
p2 (conversions in C (or not?))
Confused Cornelius posts the following question on EdStem:
I am trying to write a function that takes in an
intand converts it to hex. Here's what I've gotten so far:
int convert_to_hex(int num) { // I'm stuck here...I read over the slides and notes about doing decimal-hexadecimal conversions but I'm still confused. I can code the arithmetic, but I'm not sure what my final result should really be...?
Help Cornelius out by making a reply to his Ed question.
p3 (base conversions using gdb)
Complete the following table with the help of gdb. Please don't use some
random website that you found on Google. You know who you are.
For binary, write 8 digits, padding with leading zeroes if necessary. Note that the underscore is there purely for readability.
| Decimal | Binary | Hexadecimal |
|---|---|---|
| 254 | ||
| 0b0110_0101 | ||
| 0xd6 |