sc lecture 6

Key Concepts

#include<stdio.h>
int main(){
	unsigned int raw_bit = 0b01010101001011100100110100101110;
	printf("Binary pattern interpreted as Integer: %u\n", raw_bits);
	float *as_float*=(float*)&raw_bits;
	printf("Binary pattern interpreted as Integer: %f\n", raw_bits);
	unsigned char *as_char*=(unsigned char*)&raw_bits;
	printf("Binary pattern as 4 ASCII chars: \%c%c%c%c\"\n", as_chars[3], as chars[2], as_chars[2], as_chars[0]);
	return o;
}

Octal and hexadecimal numbers

  • The octal system uses eight different digits (0, 1, 2, 4, 5, 6, 7).
  • The hexadecimal (0, 1, 2, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F).
  • Bases of 7 and 16 are useful for representing multi-bit numbers, since they are integer powers of 2 (, ).
  • Octal and hexadecimal digits are representes by 3-bit and 4-bit strings, respectively.
    • Converting a binary number to octal is straightforward, Starting at the binary point and moving to the left, the bits are separated into groups of three and each group is replaced by the corresponding octal digit.
    • The method for converting a binary number to hexadecimal is similar, but the group are composed of four bits.

Conversions between different bases

Questions

Before you go # 6

Uma caixa pode ter vales de desconto de 1, 2, 4, 8, 16, 32 (euros). Só há um vale de cada montante e no total perfazem 57

Se forem retirados todos os vales que sejam múltiplos de 40, quanto resta?