Ch2: Data Representation Flashcards

(23 cards)

1
Q

What are the 4 number systems and their bases

A

Binary: 2
Octal: 8
Decimal: 10
Hexadecimal: 16
Conversion: base^(0-7) * binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The different bases are represented with which symbols

A

Decimal: none
Binary: 0b
Octal: 0
Hex: 0x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to convert binary to decimal?

A

Add up powers of 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to convert binary to octal?

A

Convert every 3 binary bits to octal digit (add within those 3 bits)
(421 421 421)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to convert binary to hex?

A

Convert every 4 binary bits to hex digit
(8421 8421)
10-15 is A-F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to convert any base to decimal?

A

sum of (base ^ position) * value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to convert decimals to binary?

A

divide by 2 get remainder, bottom digit is leftmost bit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to convert decimals to hex?

A

divide by 16 get remainder, bottom digit is leftmost digit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the sizes of these data types:
- char
- int
- float
- double
- pointer

A
  • char: 1
  • int: 4
  • float: 4
  • double: 8
  • pointer: 8
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are key characteristics of magnitude-only bit model

A
  • for non-negative whole numbers
  • used with unsigned types
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are key characteristics of Two’s Complement bit model

A
  • allows pos + neg whole numbers
  • to represent neg #’s: flip bits, add 1
  • if leftmost digit is 1: # is neg
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are key characteristics of fixed-point bit model

A
  • represent floats and doubles
  • 11010.101
  • 2^(43210.-1-2-3)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are key characteristics of floating point bit model

A
  • binary point position is not fixed
  • has mantissa and exponent
  • -2840 = −2.840 ∗ 10^3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are key characteristics of ASCII

A
  • maps symbols to decimal values 0-255
  • stored in 1 byte
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are compound data types, list 3 examples

A
  • stores multiple values under single variable name
  • String: ordered sequence of chars
  • Arrays: ordered sequence of primitives
  • Class: contains attributes that may be primitives or other objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does this do: char myString[50];

A

Declare string (array of char primitives) of size 50 but its uninitialized (filled with garbage characters)

17
Q

char arr[] = {1, 2, 3}
what is arr

A
  • arr is constant pointer to first element
  • not pointer
18
Q

int arr[] = {100, 200, 300, 400};
how to set element at index 2?

A

arr[2] = x;
*(arr + 2) = x;
(dereference pointer to array identifier incremented by 2)
(remember [] is syntax for dereferencing)

19
Q

int arr[] = {100, 200, 300, 400};
int *p;
how to set p to element at index 2?

A

p = &arr[2];
p = arr + 2;
(remember [] is syntax for dereferencing)

20
Q

What’s the difference between defining variables of type struct with and without typedef?

A

struct AddressType addr;
vs
AddressType addr;
- with typedef, no need for struct keyword

21
Q

What are the advantages and disadvantages of unions?

A
  • unions can represent different types of data
  • only takes up size of largest type
  • but only one representation at a time
22
Q

How are structs padded

A

Padding bytes are added so struct size is multiple of largest field in struct

23
Q

What are string literals

A
  • strings enclosed with “”
  • automatically terminated with null terminator
  • if declared as array, stored where array’s stored
  • if declared with pointer, stored in read-only data segment, cannot be changed at runtime