Bit Manipulation Flashcards

1
Q

Base 10: 0- 9

Base 8: 0 - 7

Base 16: 0-9,a-f, 0,1,2,3….,8,9,a,b,c,d,e,f,0,1,…

Base 2: 0-1

A

Base 10 : decimal

Base 8: Octal

Base 16: Hexadecimal

Base 2: Binary

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

Positional Encoding

A

Each position represents some power of the base

562 = 5 x 100 + 6 x 10 + 2 x 1 = 5 x 10^2 + 6 x 10^1 + 2 x 10^0

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

Polynomial Representation of Numbers

A

Express each column/place as a_n x b^n

28_10 (means 28 base 10 or decimal)

Represent 28_10 as a polynomial in base 10 and base 2
2 x 10^1 + 8 x 10^0

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

Converting Bases: Algorithm1

A

Repreat until val==0:
determine largest power of R that is smaller than val
- let this be R^n to get quotient and remainder
- place quotient in the result location corresponding to R^n
- val = remainder

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

Convert 71_10 to base 3

A

3^4 = 81 so must use 3^3 = 27
71 - 54 = 17
2 x 3^3 + 1 x 3^2 = 63

17 - 9 = 8 
2 x 3^3 + 1 x 3^2 + 2 x 3^1 = 69
 8-6 = 2
2 x 3^3 + 1 x 3^2 + 2 x 3^1  + 2 x 3^0 = 71
2122_3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Converting Bases: Algorithm2

A

To convert from base 10 to base R

  1. Start with R^0 position (let n=0)
  2. repreat until val==0:
    - divide val by R to produce a quotient and remainder
    - - place remainder in the R^n position, val = quotient, n++
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Convert 671_10 to base 3 with algorithm1

A

71/3 = 23 r 2

23/3 = 7 r 2

7/3 = 2 r 1

2/3 = 0 r 2

thus 2212_3

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

Converting between Binary and hex octal

1011100111

be careful in C int x = 033 ! = int x = 33

A

Just group the bits in groups of 4 and read from the right

[00]10 | 1110 | 0111
2 e 7
0 0 1 0 is 2 in decinmal, so 2 in hex is 2
1 1 1 0 is 14 in decimal, so 14 in hex is E (or e)
0 1 1 1 is 7 in decinmal, so 7 in hex is 7

For octal, group the bits in groups of 3 (starting from right)
1 | 011 | 100| 111
1 in decimal is 1
1 1 in decimal is 3
1 0 0 in decimal is 4 
1 1 1 in decimal is 7
Thus octal is 1347
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Convert from binary to decimal, octal, and hex

1 1 0 0 1 1 1 1

A

Decimal :
HEX: 1 1 0 0 | 1 1 1 1 = 12 | 15 = c | f
0xcf

Octal: 0 1 1 | 0 0 1 | 1 1 1 = 3 | 1 | 7
(null) 317

Decimal : 1 + 2 +4+ 8+ 64 + 128 = 207

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

Big Idea: Bits can represent ANYTHING

A

for Alphabet of 26 characters we use 2^5 = 32 more than enough to represent all alphabet. If we wanted to reperesent all cases (upper/lower) and punctuations we need 7 bits (ASCII)

Logical Value 0 =false 1=true

Colors: Red 00 , Green 01, Blue 11

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

Char is 1 byte

short is 2 byte

int is 4 byte

long is 8 byte

A

smallest biggest
unsigned char 0 255
char -128 127
unsigned short 0 65535
short -32768 32767
uint32_t (usually int). 0 2^(32) -1
int32_t (usually int). - 2^(31) - 1 2^(32) -1

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

How to addd two numbers in binary ?

14 + 11

A

same as decimal align and add , remember to carry

14 = 1 1 1 0
11 = 1 0 1 1
-> 1 1 0 0 1

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

How to subtract two numbers in binary ?

14 - 11

A

same as decimal align and subtract , remember to carry

14 = 1 1 1 0
11 = 1 0 1 1
-> 0 0 1 1
3

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

How to multiply?

5 x 3

A
In a sense its the same, or AND &
5 = 1 0 1
3 = 0 1 1
=     1 0 1 , then 1 0 1, then 0 0 0 , so we have (pad the right with a 0 each iteration)
         1  0  1
      1  0  1  0 
   0 0 0 0 0
= 0  1  1   1  1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to divide?

12 / 3

A
12 = 1 1 0 0
3 = 1 1 

1 1 | 1 1 0 0 (long division)

get 1 0 0 which is 4 in binary

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

How to multiply and divide by powers of 2?

10, 20 ,40 , 5

A

10 = 1 0 1 0

if we wanted 20 just pad the right with 0
20 = 1 0 1 0 0
this works since now the highest value place is now 16 plus a 4

if we want 40 jsut pad another 0 to current value.
40 = 1 0 1 0 0 0
Thus idea is padding a 0 will double the value in decimal

to get 5 we remove so 10 removes from right. a 0
1 0 1 instead of 1 0 1 0

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

Fixed point (decimal value)

2^2. 2^1. 2^0. 2^-1. 2^-2. 2^-3 …..

10/4 = 2.5

A

10/4

10 = 1 0 1 0
4 = 1 0
Do longidivision and get 1 0 . 1
1 x 2^1 + 0 x 2^0 + 1 x2^-1 = 2 +1/2

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

10/8 in binary

A

is 1.25 or 1 . 0 1

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

Company that does music transportation

A

Giga Hertz

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

Waht do we want out of a number systm that inclues both positive and negative numbers

A

Symmetric

one / zero represntation

easy to detect + / -

easy to transition

21
Q

How to represent negative numbers?

3-bit binary has a total of 8 values

A

Circular (see visual)

000 001 010 011 100 101 110 111

000 is consided positive 0
100 is considered negative zero but ignored

ANYTHING with a 1 infront is NEGATIVE

22
Q

One’s Complement

000 & 111

A

111 & 000 are each others compliment thus represent similar things

1 0 1 is complemented by 0 1 0 which are -2 and 2

1 1 0 and 0 0 1 are complements and are -1 and 1

23
Q

Two’s Complement

A

Flip all bits (&) and add a 1 to the right position

5 = 0 1 0 1 , then flip. 1 0 1 0 then 1 0 1 1

24
Q

What is the binary number 0101 1110 1010 1100 in hexadecimal?

A

0x5eac

25
Q

Binary Arithmetic

A

Addition: Unsigned , signed, fractions

Multiplying: Unsigned, signed, fractions

Foating point arithmetic

26
Q
Adding signed numbers (easy): 6 + 7
     1 1 0 (carry) 
   0 1 1 0  :6
\+ 0 1 1 1   :7
-----------
   1 1 0 1
A
1 1 0 1  (carry)
   0 1 1 0  :13 
\+ 0 1 1 1   :5
-----------
   1 1 0 1
27
Q

Adding unsigned numbers : -2 + 3

    1 1 1 0 (carry) 
   1 1 1 0  : -2
\+ 0 0 1 1   : 3
-----------
   0 0 0 1   : 1
A
1 1 1 0 (carry) 
   1 0 1 1  : -5
\+ 0 0 1 1   : 3
-----------
   1 1 1 0   : -2
28
Q

how to convert 5 to -5?

A

5 in binary is 0 1 0 1
-5 is the complement

0 1 0 1 to. 1 0 1 0

then add 1 to right 1 0 1 0 to 1 0 1 1

29
Q
Adding signed fractions: 1/4 + 3/8
   1 1 1 0 (carry)
      1 1 1 0    : - 0.25
\+    0 0 1 1   : 0.375
-------------
     0 0 0 1  

0 0 0 1 is 1/8 or 0.125

A
- 0.625 + 0.375  
   0 1 1 (carry)
      1 0 1 1   : - 0.625
\+    0 0 1 1  : 0.375
-------------
     1  1  1  0  

1 1 1 0 is -1/4 or -0.25

30
Q

Prefixes help to identify the system (binary, hex, etc.)

what is prefix for hexadecimal?

What is prefix for binary?

A

Hexadecimal is 0x

Binary is 0b

31
Q

Compare Binary value to decimal value

Binary Value	Decimal Value
         0                    0  
         1                      1  
         10                    2  
         11                     3  
         100                  4  
         101                   5
A
Binary Value	Decimal Value
         0                    0  
         1                      1  
         10                    2  
         11                     3  
         100                  4  
         101                   5  

The position of each bit in the number determines how important that bit is to the numerical value of the number. Labeling the digits from right to left as d0, d1, d2, etc., each successive bit contributes a factor of two more than the next.

32
Q

There’s no number you can represent in one system that you can’t represent in another.

PReference may sometimes be hexadecimal (16)

A

Binary bit sequences quickly grow to a large number of digits. Humans tend to have a tough time making sense of long sequences containing only 0’s and 1’s. While decimal is more compact, its base of 10 is a mismatch with binary’s base 2.

Decimal doesn’t easily capture the range that can be expressed using a fixed number of bits.

33
Q

Why is hexadecimal used?

A

The large base allows each digit to represent enough information for hexadecimal numbers to be compact.

The position of each digit in the number determines how important that digit is to the numerical value of the number. Labeling the digits from right to left as d0, d1, d2, etc., each successive digit contributes a factor of sixteen more than the next.

34
Q

Quiz 1 is due : Tuesday

A

Tuesday

35
Q

Assignments cannot be submited late

A

NO, can not be submitted late

36
Q

How many assignments can be dropped?

A

1

37
Q

To get help , do not use autograder

A

do not use autograder

38
Q

Looking at another student’s homework assignment violates AI

A

violation

39
Q

Helping a fellow student debug their code violates AI

A

violation

40
Q

Collaboration with other studnets on quizzes and assignments is not allowed

A

violation

41
Q

given two hands with 3 fingers, you would be counting base:

A

7

42
Q

convert to hexadecimal : 1100000011011110

A

1100 0000 1101 1110
0x. C 0 (zero) D. E

12
0
13
14

43
Q

convert to binary. 0xcafdfb07

A

0x. cafdfb07

1100
1010
1111
1101
1111
1011
0000
0111
44
Q
Convert to 6-bit 2's complement representation
-16
13
-3
-10
26
-31
A
  • 16: 110000
    13: 001101
  • 3: 111101
  • 10: 110110
    26: 011010
  • 31: 100001

double check

45
Q

3b)

- 48

A

-48

46
Q

42/16 in unsigned decimal where decimal point is positioned in the middle

A

42/16 = 2 5/8 = 2.625

_ _ _ _ | _ _ _ _

0 0 1 0 for 2
1 0 1 0 for the .626 since the first 1 is 1/2 and third is 1/8
0 0 1 0 1 0 1 0

47
Q

Do 8-bit 2’s complemnts representation on the following two binary-numbers

0 0 1 1 0 1 1 1
x 0 0 0 0 1 0 1 1
———————–

A
0 0 1  1  0 1 1 1
x 0 0 0 0 1 0 1 1
-----------------------
technically
   0 0 1  1  0 1 1 1
x               1 0 1 1
-----------------------

0 0 1 1 0 1 1 1
0 1 1 0 1 1 1 0
0 0 0 0 0 0 0 0
1 1 0 1 1 1 0 0 0

48
Q

0 1 1 1 + 1 0 0 0

0 1 1 0 + 0 1 0 0

A

are 4-bit overflow