โ๐ป~ 11.10
[0612] ์ฐ์ฐ์, ๋นํธ ์ฐ์ฐ์๋ก ๋ฐ์ดํฐ ๊ฐ ์ถ์ถํ๊ธฐ
Nsso
2023. 6. 13. 01:22
๐ง ์ฐ์ฐ์
์ข ๋ฅ | ์ฐ์ฐ์ | ์ค๋ช |
์ฐ์ ์ฐ์ฐ์ | + - * / % | ์ฌ์น ์ฐ์ฐ๊ณผ ๋๋จธ์ง ์ฐ์ฐ(%) |
๋น๊ต ์ฐ์ฐ์ | == !== > >= < <= | ํฌ๊ณ ์์๊ณผ ๊ฐ๊ณ ๋ค๋ฆ์ ๋น๊ต |
๋ ผ๋ฆฌ ์ฐ์ฐ์ | && || | AND (๊ทธ๋ฆฌ๊ณ ) ์ OR (๋๋) ์ผ๋ก ์กฐ๊ฑด ์ฐ๊ฒฐ |
๋์ ์ฐ์ฐ์ | = | ์ฐ๋ณ์ ๊ฐ์ ์ข๋ณ์ ์ ์ฅ |
๊ธฐํ | (type) ? : instanceof | ํ๋ณํ ์ฐ์ฐ์, ์ผํญ ์ฐ์ฐ์, Instance of ์ฐ์ฐ์ |
- ๋ ผ๋ฆฌ ์ฐ์ฐ์
์ฐ์ฐ์ | ์กฐ๊ฑด |
&& | ๋ ํญ์ด ๋ชจ๋ ์ฐธ์ธ ๊ฒฝ์ฐ์๋ง ์ฐธ. ๊ทธ๋ ์ง ์์ ์ ๊ฑฐ์ง. |
|| | ๋ ํญ ์ค ํ ํญ์ด๋ผ๋ ์ฐธ์ผ ๊ฒฝ์ฐ ์ฐธ. |
=> ์ด๋ &&์ ๊ฒฝ์ฐ์๋ (2 >= x) && (x <= 4) ์ฒ๋ผ x๋ฅผ ๊ฐ์ด๋ฐ์
|| ์ ๊ฒฝ์ฐ์๋ (x <= 2) || (4 <= x) ์ฒ๋ผ x๋ฅผ ๋ฐ๊นฅ์๋ค๊ฐ ์ ์ด์ฃผ๋ ๊ฒ ๋ณด๊ธฐ ์ฌ์
- ์ฆ๊ฐ/ ๊ฐ์ ์ฐ์ฐ์
์ฐ์ฐ์ | ๊ธฐ๋ฅ |
++ i (์ ์ํ) | ๊ฐ์ด ์ฐธ์กฐ๋๊ธฐ ์ ์ ์ฆ๊ฐ์ํด |
i ++ (ํ์ํ) | ๊ฐ์ด ์ฐธ์กฐ๋ ํ์ ์ฆ๊ฐ์ํด |
-- i (์ ์ํ) | ๊ฐ์ด ์ฐธ์กฐ๋๊ธฐ ์ ์ ๊ฐ์์ํด |
i -- (ํ์ํ) | ๊ฐ์ด ์ฐธ์กฐ๋ ํ์ ๊ฐ์์ํด |
ex)
public class Test01 {
public static void main(String[] args) {
int i =3;
i++;
System.out.println(i);
++i;
System.out.println(i);
System.out.println(++i);
System.out.println(i++);
System.out.println(i);
}
}
//์ถ๋ ฅ๊ฐ : 4, 5, 6, 6, 7
- ์ผํญ ์ฐ์ฐ์
์กฐ๊ฑด์ ? ๊ฒฐ๊ณผ 1 : ๊ฒฐ๊ณผ 2 => ์กฐ๊ฑด์ ๊ฐ์ด ์ฐธ์ด๋ฉด ๊ฒฐ๊ณผ1, ๊ฑฐ์ง์ด๋ฉด ๊ฒฐ๊ณผ 2
ex ) int num >18? true : false ;
- ๋นํธ ์ฐ์ฐ์
์ฐ์ฐ์ | ์กฐ๊ฑด | ์์ 3 = 0011 / 7 = 0111 |
& (๋นํธ ๊ต์งํฉ ์ฐ์ฐ์) | ๋์๋๋ ๋นํธ๊ฐ 1์ด๋ฉด 1 ๋ฐํํจ | 3 & 7 → 0011 |
| (๋นํธ ํฉ์งํฉ ์ฐ์ฐ์) | ๋์๋๋ ๋นํธ๊ฐ ๋ ์ค ํ๋๋ง 1์ด๋ฉด 1์ ๋ฐํํจ | 3 | 7 → 0111 |
^ (๋นํธ ์ฐจ์งํฉ ์ฐ์ฐ์) | ๋์๋๋ ๋นํธ๊ฐ ์๋ก ๋ค๋ฅด๋ฉด 1์ ๋ฐํํจ | 3 ^ 7 → 0100 |
~ (๋นํธ ๋ถ์ ์ฐ์ฐ์) | ๋นํธ๊ฐ 1์ด๋ฉด 0์ผ๋ก, 0์ด๋ฉด 1๋ก ๋ฐ์ ์ํด | ~3 → 1100 |
- ์ฌํํธ ์ฐ์ฐ์
์ฐ์ฐ์ | ์กฐ๊ฑด | ์์ |
<< (์ผ์ชฝ ์ฌํํธ ์ฐ์ฐ์) | ์ฃผ์ด์ง ์ซ์๋งํผ ์ผ์ชฝ์ผ๋ก ์ด๋์ํด | 3 << 2 → 0011 << 2 → 1100 → 12 |
>> (์ค๋ฅธ์ชฝ ์ฌํํธ ์ฐ์ฐ์) | ์ฃผ์ด์ง ์ซ์๋งํผ ์ค๋ฅธ์ชฝ์ผ๋ก ์ด๋์ํด | 3 >> 2 → 0011 >> 2 → 0000 → 0 |
๐ง ์ฐ์ฐ์์ ๊ฒฐํฉ ๊ท์น
- ์ฐ์ > ๋น๊ต > ๋ ผ๋ฆฌ > ๋์ ์
- ๋จํญ > ์ดํญ > ์ผํญ ์
- ๋จํญ ์ฐ์ฐ์์ ๋์ ์ฐ์ฐ์๋ฅผ ์ ์ธํ ๋ชจ๋ ์ฐ์ฐ์ ์งํ ๋ฐฉํฅ์ ์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ
์ฐ์ฐ์ | ์์ |
๋จํญ ์ฐ์ฐ์ | i ++ |
์ดํญ ์ฐ์ฐ์ | num1 + num2; |
์ผํญ ์ฐ์ฐ์ | int num >18 ? true : false ; |
๐ง ๋น ์๋์(Big Endian)๊ณผ ๋ฆฌํ ์๋์(Little Endian) _ ๋ฐ์ดํธ ์ ์ฅ ์์
๋ฐ์ดํธ ์ ์ฅ ์์(Byte Order)๋?
=> ์ปดํจํฐ ๋ฉ๋ชจ๋ฆฌ์ ๋ฐ์ดํธ๊ฐ ์ ์ฅ๋๋ ์์๋ฅผ ๋งํ๋ฉฐ ๊ทธ์ ๋ฐ๋ผ ๋น ์๋์ ๋ฐฉ์๊ณผ ๋ฆฌํ ์๋์ ๋ฐฉ์์ผ๋ก ๋๋จ
๋น ์๋์ (Big Endian)
- ์ฐ๋ฆฌ๊ฐ ์ผ์ชฝ๋ถํฐ ์ฝ์ด๋๊ฐ๋ ๋ฐฉ์๊ณผ ๋น์ทํจ
- ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ๋ ์์ ๊ทธ๋๋ก ์ฝ์ ์ ์์ด ์ดํดํ๊ธฐ ์ฌ์
- ๋ฎ์ ์ฃผ์์ ๋ฐ์ดํฐ์ ๋์ ๋ฐ์ดํธ๋ถํฐ ์ ์ฅํ๋ ๋ฐฉ์
- ๋คํธ์ํฌ๋ฅผ ํตํ ๋ฐ์ดํฐ ์ ์ก ์ ์ฃผ๋ก ์ฌ์ฉ๋จ
- ๋น๊ต ์ฐ์ฐ์์ ๋ฆฌํ ์๋์๋ณด๋ค ๋น ๋ฆ
๋ฆฌํ ์๋์ (Little Endian)
- Big Endian๊ณผ ๋ฐ๋
- ์์ ๋จ์๊ฐ ์์ ๋์ค๋ ๊ฒ์ ๋งํจ
- ๋๋ถ๋ถ์ ์ธํ CPU ๊ณ์ด์์ ํด๋น ๋ฐฉ์์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํจ
- ๋ฎ์ ์ฃผ์์ ๋ฐ์ดํฐ์ ๋ฎ์ ๋ฐ์ดํธ๋ถํฐ ์ ์ฅํ๋ ๋ฐฉ์
- ์ฐ์ ์ฐ์ฐ์์ ๋น ์๋์๋ณด๋ค ๋น ๋ฆ
๐ง ์์ฉ ์์
Q. ์ฐ์ฐ์๋ฅผ ์ด์ฉํด ์ด๋ฏธ์ง ํ์ผ ํฌ๊ธฐ ์ถ๋ ฅํด ๋ณด๊ธฐ
์กฐ๊ฑด : ์ฝ์ด์ฌ ์ด๋ฏธ์ง๋ฅผ 24bit๋ก ์ ์ฅํ๊ธฐ
โ๐ป ์ด ๋ฌธ์ ์ ํต์ฌ ๋ฐ ํ์ด
๋๋ณด๊ธฐ




- ๋นํธ๋งต ํ์ผ์ Signature (2byte)๋ฅผ ์ ์ธํ๊ณ ๊ฐ ๊ณ์ธต๋ง๋ค ํด๋น ์ด๋ฏธ์ง์ ์ ๋ณด(4byte)๋ค์ ๋ด๊ณ ์์
- ๊ทธ๋ฌ๋ฏ๋ก ๋ฌธ์ ์์ ์๊ตฌํ Image Width์ Image Height๋ฅผ ์ถ์ถํ๋ ค๋ฉด ๊ทธ ์ ๊น์ง์ 18byte๋ฅผ ๊ฑท์ด๋ธ ํ
Image Width(19~22 byte) ์ Image Height(23~26byte)์ ํด๋นํ๋ ๊ฐ์ ์ฝ์ด์ค๋ฉด ๋จ
์์ฑ ์ฝ๋)
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;
public class Test01 {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("res/pic1.bmp");
Scanner fscan = new Scanner(fis);
// Image Width ๋๋ฌ ์ ๊น์ง์ 18byte ์ ์ธ
//Signautre
fis.read(); fis.read();
//Filesize
fis.read(); fis.read();
fis.read(); fis.read();
//Reserved 1,2
fis.read(); fis.read();
fis.read(); fis.read();
//File offset to pixel Array
fis.read(); fis.read();
fis.read(); fis.read();
//Dib header size
fis.read(); fis.read();
fis.read(); fis.read();
// Width ๋ถ๋ถ 1byte์ฉ ์ฝ์ด์ค๊ธฐ
int w1 = fis.read();
int w2 = fis.read();
int w3 = fis.read();
int w4 = fis.read();
// Height ๋ถ๋ถ 1byte์ฉ ์ฝ์ด์ค๊ธฐ
int h1 = fis.read();
int h2 = fis.read();
int h3 = fis.read();
int h4 = fis.read();
//๊ฑฐ๊พธ๋ก ์ฝํ ๋ฐ์ดํฐ ๊ฐ ํ์ธํ๊ธฐ
System.out.printf("%d,%d,%d,%d", w1, w2, w3, w4);
System.out.printf("%d,%d,%d,%d", h1, h2, h3, h4);
// Shift ์ฐ์ฐ์๋ฅผ ํตํด ๋ค์ ๋ค์ง๊ธฐ
int width = w1 << 0 | w2 << 8 | w3 << 16 | w4 << 24;
int height = h1 << 0 | h2 << 8 | h3 << 16 | h4 << 24;
// ์ ์๋ ์ถ๋ ฅ๊ฐ ํ์์ผ๋ก ํ์ผ๋ช
์ถ๋ ฅ
System.out.println(width + " * " + height);
}
}


- ํด๋น ์ด๋ฏธ์ง ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ํ๋ก๊ทธ๋จ์ ํตํด ์คํํ๋ฉด ๊ฑฐ๊พธ๋ก ์ ์ฅ๋์ด์๋ ๊ฐ์ 10์ง์๋ก ํ์ธํ ์ ์์ผ๋ฉฐ
- ๋ค์ ์์๋ฅผ ๋ค์ง์ด ์ ์ฅํด์ฃผ์ด์ผ ํ๊ธฐ ๋๋ฌธ์ Shift ์ฐ์ฐ์๋ฅผ ํตํด1byte (8bit) ์ฉ
๊ฐ๊ฐ 0, 8, 16, 24 bit์ฉ ๋ฐ์ด์ค์ผ ํจ