Bits and Bytes Hex Digit Bit Pattern

Slides:



Advertisements
Similar presentations
Literals Why does this produce an error? float x = 2.5;
Advertisements

Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
18-May-15 Numbers. 2 Bits and bytes A bit is a single two-valued quantity: yes or no, true or false, on or off, high or low, good or bad One bit can distinguish.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
2.2 General Positional-Number-System Conversion
Integer Types. Bits and bytes A bit is a single two-valued quantity: yes or no, true or false, on or off, high or low, good or bad One bit can distinguish.
Agenda Shortcuts converting among numbering systems –Binary to Hex / Hex to Binary –Binary to Octal / Octal to Binary Signed and unsigned binary numbers.
1 Section 2.5 Integers and Algorithms. 2 Euclidean algorithm for finding gcd Where L is a larger number, and S is a smaller number, to find gcd(L,S):
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
1 Number Systems. 2 Numbers Each number system is associated with a base or radix – The decimal number system is said to be of base or radix 10 A number.
Unsigned and Signed Numbers. Hexadecimal Number 217A 16 Position Digits A Value = 2x x x16 + Ax1 = 2x x x16.
Binary Number Systems.
Binary and Hexadecimal Numbers
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
1 Programming in Machine Language SCSC 311 Spring 2011.
Bit Manipulation when every bit counts. Questions on Bit Manipulation l what is the motivation for bit manipulation l what is the binary, hexadecimal,
The Teacher CP4 Binary and all that… CP4 Revision.
Number Representation. Representing numbers n Numbers are represented as successive powers of a base, or radix.
Number System. Number Systems Important Number systems – Decimal – Binary – Hexadecimal.
Bitwise operators. Representing integers We typically think in terms of decimal (base 10) numbers.  Why?  A decimal (or base 10) number consists of.
Operations on Bits Arithmetic Operations Logic Operations
Bitwise operators. Representing integers We typically think in terms of decimal (base 10) numbers.  Why?  A decimal (or base 10) number consists of.
Bitwise Operators Fall 2008 Dr. David A. Gaitros
CS 101 – Aug. 31 Interpreting binary  decimal √ Decimal  binary Shorthand ways of expressing binary –Octal –“Hex” Negative numbers.
Working with 8-bit bytes and hexadecimal
Hexadecimal Data Representation. Objectives  Know how the Hexadecimal counting system works  Be able to convert between denary, binary & hexadecimal.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Binary 101 Gads Hill School. Aim To strengthen understanding of how computers use the binary number system to store information.
Reasons to  Binary With Mrs
LESSON 5 – Assignment Statements JAVA PROGRAMMING.
Chapter 8 Bit Operations By C. Shing ITEC Dept Radford University.
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
August 6, Operators. August 6, Arithmetic Operators.
Two’s Complement The language of machines, part II.
Base 16 (hexadecimal) Uses the decimal digits and the first letters of the alphabet to encode 4 binary bits (16=2 4 ) abcdef or ABCDEF.
CompSci From bits to bytes to ints  At some level everything is stored as either a zero or a one  A bit is a binary digit a byte is a binary.
ME2008– W05 MID1- Reference 2016Q1- Source: Deitel /C- How To.
From bits to bytes to ints
Numbers Mar 27, 2013.
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Numbers in a Computer Unsigned integers Signed magnitude
Number Systems.
EPSII 59:006 Spring 2004.
Number Systems and Bitwise Operation
What to bring: iCard, pens/pencils (They provide the scratch paper)
Chapter 14 Bitwise Operators Objectives
Operators August 6, 2009.
Binary Lesson 3 Hexadecimal
Bits, Bytes, and Integers 2nd Lectures
Bits and Bytes Topics Representing information as bits
Binary Lesson 3 Hexadecimal
Binary Lesson 3 Hexadecimal
Homework Homework Continue Reading K&R Chapter 2 Questions?
Binary Lesson 3 Hexadecimal
Comp Org & Assembly Lang
Number Systems Rayat Shikshan Sanstha’s
Numeral systems (radix)
Bitwise Operators.
Binary Lesson 4 Hexadecimal and Binary Practice
Numbers 27-Apr-19.
Number Systems Rayat Shikshan Sanstha’s
Bitwise operators.
Module 10 Operations on Bits
Numbers 6-May-19.
Lecture 2: Bits, Bytes, Ints
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

Bits and Bytes Hex Digit Bit Pattern 0000 1 0001 2 0010 3 0011 4 0100 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 a 1010 b 1011 c 1100 d 1101 e 1110 f 1111 One bit stores either 0 or 1. One byte is a sequence of 8 bits. One Java int is a sequence of 4 bytes or 32 bits. Each half (nibble) of a byte can be represented by a single hexadecimal digit. To express Java data (int) in hexadecimal use… 0xHHHHHHHH where "H" is one hex digit Examples 0x00ffffff 0xff00ffff 0xab

Bitwise Operations Hex Digit Bit Pattern 0000 1 0001 2 0010 3 0011 4 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 a 1010 b 1011 c 1100 d 1101 e 1110 f 1111 & means bitwise AND Each bit is treated as follows: 0 & 0  0 0 & 1  0 1 & 0  0 1 & 1  1 | means bitwise OR Each bit is treated as follows: 0 | 0  0 0 | 1  1 1 | 0  1 1 | 1  1 Example int bits = 0xabcdefab; bits = bits & 0xff00ffff; bits = 0xabcdefab; bits = bots | 0xff00ffff;

More Bitwise Operations Hex Digit Bit Pattern 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 a 1010 b 1011 c 1100 d 1101 e 1110 f 1111 <<< n means shift left by n (n is an integer) >>> n means shift right by n (n is an integer) Example int bits = 0x00abcdefab; bits = bits >>> 8; bits = bits <<< 8; bits = 0xff00ffff; bits = bits >>> 16; Two more things… 1) A cast to byte returns the rightmost byte of int, long or short data. 2) Treating a byte as an int, short or long sign extends. Example int bits = 0x00abcdefab; byte oneByte = (byte)bits; bits = oneByte;