rgb() 값은 왜 0~ 255까지일까?

Yoseob Shin·2023년 10월 22일
0

CS

목록 보기
4/4

보통 css를 작성시 color: rgb(number, number, number)에서 number값을 넘겨 색상을 정한다. 여기서 numbers는 0~255까지 넘길수 있는데 왜 0에서 255 까지인지 궁금해 졌다.

The way that computers do this is that they have lots of little switches in their memory which we call bits. Bits can only have one of two values, a one or a zero. Bits are arranged into groups of eight switches called bytes.

0) 컴퓨터 메모리의 가장 작은 유닛을 bit이라 한다.
1) 하나의 bit은 0, 1 값만 있고 이렇게 두가지의 값중 하나만 저장 할수 있다.
2) 1 byte은 8 bits로 구성되어 있다.

  1. byte은 8bits로 구성되어 있으니 1byte의 값이 가질수 있는 변수값은:

    2x2x2x2x2x2x2x2 = 256

쉽게 말하면 1byte은 256가지의 다른 값을 가질수 있다는 말이다.

그치만 컴퓨터 프로그래밍에선 숫자는 0부터 시작하니 0-255로 사용 되고 있다.

  1. rgb(255, 255, 255), 처럼 rgb()함수에 세가지 숫자 파람을 넣는다고 하자. 그러면 3 byte을 넣는거지:

    256x256x256= 16777216

16777216가지 종류의 값을 얻을수 있다.

css에서도 컴퓨터 공학의 기초를(?) 알게되는 좋은 기회 였다.

Source: Goldsmiths University BS.cComputer Science 과정

profile
coder for web development + noodler at programming synthesizers for sound design as hobbyist.

0개의 댓글

관련 채용 정보