1 / 14

Bits and Bytes

Bits and Bytes. COMP 21000 Comp Org & Assembly Lang. Topics Why bits? Representing information as bits Binary / Hexadecimal Byte representations Numbers Characters and strings Instructions Bit-level manipulations Boolean algebra Expressing in C. Converting. main() {

lbien
Download Presentation

Bits and Bytes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bits and Bytes COMP 21000 Comp Org & Assembly Lang Topics • Why bits? • Representing information as bits • Binary / Hexadecimal • Byte representations • Numbers • Characters and strings • Instructions • Bit-level manipulations • Boolean algebra • Expressing in C

  2. Converting main() { octal_print(0); /* result: 00 */ octal_print(-1); /* result: -01 */ octal_print(123456); /* result: 0361100 */ octal_print(-123456); /* result: -0361100 */ octal_print(0123456); /* result: 0123456 since 0 at */ /* beginning indicates octal num */ octal_print(-0123456); /* result: -0123456 */ octal_print(999); /* result: 01747 */ octal_print(-999); /* result: -01747 */ octal_print(1978); /* result: 03672 */ }

  3. Converting #define DIG 20 void octal_print(int x) { int i = 0, od; char s[DIG]; /* up to DIG octal digits */ if ( x < 0 ) /* treat negative x */ { putchar ('-'); /* output a minus sign */ x = - x; } do { od = x % 8; /* next higher octal digit */ s[i++] = (od + '0'); /* octal digits in char form */ } while ( (x = x/8) > 0); /* quotient by integer division */ putchar('0'); /* octal number prefix */ do { putchar(s[--i]); /* output characters on s s*/ } while ( i > 0 ); putchar ('\n'); putchar ('\n'); } See /home/barr/Student/comp210/examples/octal.c

  4. Memory • What is memory (RAM)? • To the processor, it’s just a big array of cells • Each cell has an address • Each cell contains a specific value 0 1 2 3 4 Address Contents

  5. Memory • Of course, addresses and content are actually in binary Memory is byte addressable i.e., every byte has an address. Address 000 001 010 011 100 Contents

  6. Memory • When we look at memory in a debugger (like gdb), usually use hex notation Address 000 001 002 003 004 Contents

  7. Memory What we see (gdb) x/20b 0x7fffffffe45c 0x7fffffffe45c:0x5 0x0 0x0 0x0 0x1 0x0 0x0 0x0 0x7fffffffe464:0x0 0x0 0x0 0x0 0xffffffffffffffdd 0x50x40 0x0 0x7fffffffe46c:0x0 0x0 0x0 0x0

  8. Addressing Memory CPU must send an address to RAM how many bits in the address? depends on how many wires there are! 32-bit machine means 32 wires on each bus

  9. Memory • How do we talk about the size of memory? • in terms of powers of 2 (addresses are binary) Bus must have 3 wires Memory size limited by number of bits in address: 3 bits so 8 cells

  10. Range An address has a fixed number of bits. The range is the numbers that will fit in that many bits. Examples: 0 0 0 = 0 1 1 1 = 7 range is 0 to 7 0 0 0 0 = 0 1 1 1 1 = 15 range is 0 to 15

  11. Range In general range is 0 to 2n – 1 where there are n bits in the representation Intuition: • 111 = 1 x 22 + 1 x 21 + 1 x 20 Which is 1 less than 1000 = 1 x 23 + 0 x 22 + 0 x 21 + 0 x 20 Number of numbers represented: • n bits can represent 2n different numbers • i.e., from 0 to 2n – 1

  12. Size In general Size is 2n where there are n bits in the representation Intuition: • Range of 3 bits: 0 0 0 = 0 1 1 1 = 7 range is 0 to 7 number of numbers is 8 = 23 or 1 more than the largest number! Number of numbers represented: • n bits can represent 2n different numbers • i.e., from 0 to 2n – 1

  13. Memory • How do we talk about the size of memory? • in terms of powers of 2 (addresses are binary) based on the number of bits in the address

  14. Memory • How do we talk about the size of memory? • in bytes (how may bytes of memory do you have?) • in terms of powers of 2 (addresses are binary) 1 bit 1 byte 1 Kilobyte (Kb) 1 Megabyte (Mb) 1 Gigabyte (Gb) 1 Terabyte (Tb)

More Related