====== CBYTE ====== /* Remove the comments after creating content for each section.*/ Converts a given value to a value that can fit within a byte /* For the lines below, just create links, separated by commas, to other pages of the BASICs section, like [[:basics:basicTagName]]. "Implemented by" should mention BASICs which implement the keyword like described, in a more usual and standard way. "With variations" should point to BASICs where this keyword is used a bit differently. "Also written as" should list alternative spellings and abbreviations this keyword has. No need to refer to a BASIC, there is a section for that later. */ **Implemented by:** [[:basics:FreeBASIC:]], [[:basics:Gambas:]] **With variations:** **Also written as: ** ''__Cbyte'' under FreeBASIC's //-lang qb// compiler option ===== Usage ===== /* For inline examples of syntax, write the keyword between '' and '' (two single quotes) */ CBYTE turns a value into a byte-sized value — whatever this might account for. [[:basics:freebasic|FreeBASIC]] wraps the given value into a signed byte value. Officially, _"results are undefined"_ for values lesser than -128 or greater than 127, and there is no checking for overflows, but the compiler issues warnings if the value is greater than the unsigned byte limit (255). PRINT CBYTE(127) '127 PRINT CBYTE(128) '-128 PRINT CBYTE(129) '127 PRINT CBYTE(255) '-1 PRINT CBYTE(256) '0 and warning "Overflow in constant conversion" PRINT CBYTE(257) '1 and warning "Overflow in constant conversion" PRINT CBYTE(258) '2 and warning "Overflow in constant conversion" PRINT CBYTE(-258) '-2 and warning "Overflow in constant conversion" According to its documentation, CBYTE accepts floating point numbers and rounds them down by cutting off the decimal part (see [[FIX]]). The function accepts non-numeric arguments, such as strings and user-defined types. FreeBASIC's documentation only states that strings are passed through the [[VALINT]] function, so a string of digits is converted to a number before the to-byte conversion. Normal strings are converted to 0. [[:basics:gambas|Gambas]] does not seem to be that open to non-numeric arguments and issues "Type Mismatch" errors if the value cannot be converted. According to its documentation, a boolean //true// is converted to 255. Also, it seems that it wraps numeric values into unsigned byte values, like FreeBASIC's [[CUBYTE]], as ''CBYTE(100000)'' returns 160 while FreeBASIC returns -96. ===== Examples ===== /* Below is an example of a code block, using GeSHi syntax highlighting for //gwbasic//. Other styles of interest might be //basic4gl//, //blitzbasic//, //freebasic//, //gambas//, //locobasic//, //purebasic//, //qbasic//, //sdlbasic//, //thinbasic//, //vb//, //vbnet//, //xbasic// or //zxbasic//. 10 PRINT "HELLO" */ ===== Comments ===== /* Origin of the keyword, opinions, history... */ ===== Related keywords ===== /* Keywords that are often or always used along this one */ * [[CUBYTE]] ===== Similar keywords ===== /* Keywords with the same or similar functionality found in other versions of BASIC */ ===== In other languages... ===== /* For parallels and comparisons with other modern-day languages */ ===== References ===== /* If you used the ((citation)) syntax elsewhere in the text, they will appear under this section. But you can write some recommendations of books, magazines, etc */ * https://gambaswiki.org/wiki/lang/cbyte , last check 2024-03-08 * https://www.freebasic.net/wiki/KeyPgCbyte , last check 2024-03-08 /* ===== TAGS ===== Please use the syntax below for adding tags to this page, separated by spaces (use quotes for tags with spaces). The most important tags to be used are, separated by groups: - Statements | Commands | SpecialVariables | Operators {{tag>tagName}} */ {{tag>Functions Conversion}}