684 ^ self retry:#bitAnd: coercing:anInteger |
684 ^ self retry:#bitAnd: coercing:anInteger |
685 |
685 |
686 "(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2" |
686 "(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2" |
687 ! |
687 ! |
688 |
688 |
689 bitClear:anInteger |
|
690 "return the bitwise-and of the receiver and the complement of the argument, anInteger, |
|
691 returning the receiver with bits of the argument cleared." |
|
692 |
|
693 %{ /* NOCONTEXT */ |
|
694 |
|
695 /* anding the tags doesn't change it */ |
|
696 if (__isSmallInteger(anInteger)) { |
|
697 RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) ); |
|
698 } |
|
699 %}. |
|
700 ^ self retry:#bitClear: coercing:anInteger |
|
701 |
|
702 " |
|
703 (2r001010100 bitClear:2r00001111) radixPrintStringRadix:2 |
|
704 " |
|
705 ! |
|
706 |
|
707 bitAt:index |
689 bitAt:index |
708 "return the value of the index's bit (index starts at 1). |
690 "return the value of the index's bit (index starts at 1). |
709 Notice: the result of bitAt: on negative receivers is not |
691 Notice: the result of bitAt: on negative receivers is not |
710 defined in the language standard (since the implementation |
692 defined in the language standard (since the implementation |
711 is free to choose any internal representation for integers)" |
693 is free to choose any internal representation for integers)" |
716 ^ self error:'index out of bounds' |
698 ^ self error:'index out of bounds' |
717 ]. |
699 ]. |
718 mask := 1 bitShift:(index - 1). |
700 mask := 1 bitShift:(index - 1). |
719 ((self bitAnd:mask) == 0) ifTrue:[^ 0]. |
701 ((self bitAnd:mask) == 0) ifTrue:[^ 0]. |
720 ^ 1 |
702 ^ 1 |
|
703 ! |
|
704 |
|
705 bitClear:anInteger |
|
706 "return the bitwise-and of the receiver and the complement of the argument, anInteger, |
|
707 returning the receiver with bits of the argument cleared." |
|
708 |
|
709 %{ /* NOCONTEXT */ |
|
710 |
|
711 /* anding the tags doesn't change it */ |
|
712 if (__isSmallInteger(anInteger)) { |
|
713 RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) ); |
|
714 } |
|
715 %}. |
|
716 ^ self retry:#bitClear: coercing:anInteger |
|
717 |
|
718 " |
|
719 (2r001010100 bitClear:2r00001111) radixPrintStringRadix:2 |
|
720 " |
721 ! |
721 ! |
722 |
722 |
723 bitInvert |
723 bitInvert |
724 "return the value of the receiver with all bits inverted" |
724 "return the value of the receiver with all bits inverted" |
725 |
725 |
2395 } |
2395 } |
2396 %}. |
2396 %}. |
2397 ^ super printString |
2397 ^ super printString |
2398 ! |
2398 ! |
2399 |
2399 |
2400 printStringRadix:radix |
2400 printStringRadix:base |
2401 "return my printstring (optimized for bases 16, 10 and 8)" |
2401 "return my printstring (optimized for bases 16, 10 and 8)" |
2402 |
2402 |
2403 %{ /* NOCONTEXT */ |
2403 |s| |
2404 |
2404 %{ |
2405 char *format = (char *)0; |
2405 char *format = (char *)0; |
2406 char buffer[30]; |
2406 char buffer[30]; |
2407 OBJ newString; |
2407 OBJ newString; |
2408 |
2408 |
2409 if (__isSmallInteger(radix)) { |
2409 if (__isSmallInteger(base)) { |
2410 switch (__intVal(radix)) { |
2410 switch (__intVal(base)) { |
2411 case 10: |
2411 case 10: |
2412 #ifdef alpha64 |
2412 #ifdef alpha64 |
2413 format = "%ld"; |
2413 format = "%ld"; |
2414 #else |
2414 #else |
2415 format = "%d"; |
2415 format = "%d"; |
2416 #endif |
2416 #endif |
2417 break; |
2417 break; |
2418 case 16: |
2418 case 16: |
2419 #ifdef alpha64 |
2419 #ifdef alpha64 |
2420 format = "%lx"; |
2420 format = "%lx"; |
2421 #else |
2421 #else |
2422 format = "%x"; |
2422 format = "%x"; |
2423 #endif |
2423 #endif |
2424 break; |
2424 break; |
2425 case 8: |
2425 case 8: |
2426 #ifdef alpha64 |
2426 #ifdef alpha64 |
2427 format = "%lo"; |
2427 format = "%lo"; |
2428 #else |
2428 #else |
2429 format = "%o"; |
2429 format = "%o"; |
2430 #endif |
2430 #endif |
2431 break; |
2431 break; |
2432 } |
2432 } |
2433 } |
2433 } |
2434 |
2434 |
2435 if (format) { |
2435 if (format) { |
2436 /* |
2436 /* |
2437 * actually only needed on sparc: since thisContext is |
2437 * actually only needed on sparc: since thisContext is |
2438 * in a global register, which gets destroyed by printf, |
2438 * in a global register, which gets destroyed by printf, |
2439 * manually save it here - very stupid ... |
2439 * manually save it here - very stupid ... |
2440 */ |
2440 */ |
2441 __BEGIN_PROTECT_REGISTERS__ |
2441 __BEGIN_PROTECT_REGISTERS__ |
2442 |
2442 |
2443 sprintf(buffer, format, __intVal(self)); |
2443 sprintf(buffer, format, __intVal(self)); |
2444 |
2444 |
2445 __END_PROTECT_REGISTERS__ |
2445 __END_PROTECT_REGISTERS__ |
2446 |
2446 |
2447 newString = __MKSTRING(buffer COMMA_SND); |
2447 newString = __MKSTRING(buffer COMMA_SND); |
2448 if (newString != nil) { |
2448 if (newString != nil) { |
2449 RETURN (newString); |
2449 RETURN (newString); |
2450 } |
2450 } |
2451 } |
2451 } |
2452 %}. |
2452 %}. |
2453 " |
2453 " |
2454 fall back for seldom used bases |
2454 fall back for seldom used bases |
2455 " |
2455 " |
2456 ^ super printStringRadix:radix |
2456 |
2457 |
2457 s := WriteStream on:(String new:10). |
2458 "123 printStringRadix:16" |
2458 super printOn:s base:base. |
2459 "123 printStringRadix:8" |
2459 ^ s contents. |
2460 "123 printStringRadix:2" |
2460 |
2461 "123 printStringRadix:3" |
2461 " |
2462 "123 printStringRadix:1" |
2462 123 printStringRadix:16 |
|
2463 123 printStringRadix:8 |
|
2464 123 printStringRadix:2 |
|
2465 123 printStringRadix:3 |
|
2466 123 printStringRadix:1 |
|
2467 " |
2463 ! |
2468 ! |
2464 |
2469 |
2465 printfPrintString:formatString |
2470 printfPrintString:formatString |
2466 "non-portable, but sometimes useful. |
2471 "non-portable, but sometimes useful. |
2467 return a printed representation of the receiver |
2472 return a printed representation of the receiver |