Lecture 2 Flashcards

1
Q

What are the data types which represent numerical values?

A
  • short 1-byte
  • int 4-bytes
  • long 4-bytes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

char

A
  • It represents one of 256 different characters.
  • we pay intention to 75 of them.
  • Why 256? because of 2 ~8 - 1= 255
  • When we say here 256 characters, but in the meanwhile, you could place only 255 digits in the binary representation for 1 byte/8bit. the answer is => Zero is considered a char here (by the way NULL), so 255 + 0 or null
  • In this case, we used all the 8 bits. shouldn’t we use all the byte and this should be normal? no in other cases we used the most left bit as a sign bit [+ -
  • https://ykode.id/under-the-bonnet-representing-characters-and-strings-ff7cec26ee3c
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the data types which represent fractional number values?

A
  • float 4-bytes

- double 8-bytes

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

What is the binary digit?

A
  • high or low voltages
  • computer scientists don’t need to view it that way, they
    just need to recognize that a bit is a very small amount of memory that can distinguish between 2 different values
  • a single bit can store zero or one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do we represent a boolean in memory?

A
  • 1 byte
  • a boolean could just be mapped to a single bit in memory
  • it turns out it’s not practical to do that but if you really wanted to use a single bit to represent a boolean variable you could engineer your compiler to do that
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to convert binary to decimal?

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

how to add binary numbers?

A

1 + 1 = 0 :]

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

how to add binary numbers?

A

1 + 1 = 0

1 + 1 + 1 = 1

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

How to represent a negative number in binary

A
  • represent the number as you do in positive case
  • flip all the numbers
  • add one to this number
    0101
    ……..
    1010
    0001
    …….
    1011
  • when the number gets bigger overflow will happen.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What short represents?

A

negative 2 to the 15th through 2 to the 15th minus 1

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

what happen when I assign short to int and the value is negative?

A

sign bit extend

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

bit patten evaluation

A

int i =5;
float f = i;
cout<

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

5.0 representation

A

1.25 x 2~2
exp = 129
xxx = .25

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

When the float evaluation could be mistakenly ignored?

A

in a case like this:

int i = 37;
float f = * (float*)&i;

please read from the right to the left!

we cheated here by casting the ptr to float while the actual bit pattern represents an int,

The compiler will think that bit evaluation is not important so it will copy it, which will give another number

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